Author Topic: TF.NET - finding intersections  (Read 6256 times)

0 Members and 1 Guest are viewing this topic.

Chris Dheere

  • Guest
TF.NET - finding intersections
« on: February 05, 2008, 07:54:37 AM »
Hi,

i am just tying to start to use the TF.net libraries.  i have created a reference to both topology.dll and topology.io.dwg.dll.
intellisense is working fine in my code, but when i execute my program i get an exception that the topology.io.dwg can not be found.

does anyone have an idea?

i would like to use this library to find intersections between polygons... do i use the spatial operations and choose intersect, or do i use the geometry.intersection?
what is the prefered method?

thanks
chris

SomeCallMeDave

  • Guest
Re: TF.NET - finding intersections
« Reply #1 on: February 06, 2008, 10:11:02 PM »
Chris,
Welcome to the Swamp!!


I haven't played much with the TF.net libs, but I didn't have that problem.  The little bit of testing that I have done worked fine.

Maybe someone else will happen along with more experience than I to answer your other question.

The TF lib looks like it has a lot of potential uses.  I hope to have more time to play with it soon

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: TF.NET - finding intersections
« Reply #2 on: February 06, 2008, 10:51:50 PM »
Hi Chris,
You may need to copy your TF.net dll's into the same folder that your custom dll is loaded from. Ref'ing them in only works for the compiler so it knows where they are but your application doesn't know how to find them if they are not with the loaded dll.
Either that or I think you can place them in the GAC so all applications have access to them if needed (it's like your windows system folder).

hth.
Mick.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

MaksimS

  • Guest
Re: TF.NET - finding intersections
« Reply #3 on: February 19, 2008, 05:38:03 AM »
Hi Chris,

Sorry for not replying earlier. You should reference both Topology.dll and Topology.IO.Dwg.dll in your project if you're intending to use it with AutoCAD. Topology.IO.Dwg.dll simply "converts" AutoCAD entities into JTS-readable geometries (or vice-versa). Besides the two, your project should also reference managed AutoCAD libraries (acdbmgd.dll, etc.) - depending on what you're trying to achieve with the whole thing. I suggest you to put all referenced libraries (yours and TF.NET ones) within the same folder and NETLOAD them from that folder.

Regards,
Maksim Sestic


Hi,

i am just tying to start to use the TF.net libraries.  i have created a reference to both topology.dll and topology.io.dwg.dll.
intellisense is working fine in my code, but when i execute my program i get an exception that the topology.io.dwg can not be found.

does anyone have an idea?

i would like to use this library to find intersections between polygons... do i use the spatial operations and choose intersect, or do i use the geometry.intersection?
what is the prefered method?

thanks
chris

MaksimS

  • Guest
Re: TF.NET - finding intersections
« Reply #4 on: February 23, 2008, 06:41:09 AM »
Hi Chris,

Regarding the intersections question - you should use Polygon's Intersects() function to determine whether geometry intersects another one (True or False). Furthermore, you could also use Intersection() function to actually access geometry considered "intersection". Keep in mind that resulting Geometry may be either polygon, linestring, or point.

In case you're trying to enumerate "crossings" in network topology (well, sort of intersection indeed), you should use set of Topology.Graph classes.

Regards,
Maksim Sestic

MaksimS

  • Guest
Re: TF.NET - finding intersections
« Reply #5 on: February 23, 2008, 06:52:03 AM »
It's simple - use DwgReader to convert closed polylines into polygons first. You can also put them into GeometryCollection, or any generic collection for that matter. Then enumerate all polygons against other polygons in collection, skipping self-crossing geometries (you don't want to check whether polygon A crosses itself). You could also put results (found intersections) into other collection, then use DwgWriter to flush resulting collection into the drawing.

TF.NET (well, JTS/NTS underneath) is indeed powerful set of geometric tools. You can easily build customized set of functions ressembling Autodesk Map 3D ones dealing with topology, maybe even more consistent ones :-)

Regards,
Maksim Sestic

Thanks for the reply.

i finally found that putting them in the autocad directory fixed the problem, thanks for that.
But now, I would like to do the following:

I have a layer that contains closed polylines that I need to compare with another layer that contains also closed polylines.
For each polyline on layer A, I need to check if it intersects with polylines on layer B and if it does, I need to draw the intersection (as a closed polyline).
Is this something that can be done with these libraries.
Can you point me in the right direction

Are there somewhere some more examples available, I found the buffer and linemerger example, but besides those  I couldn’t find much more.
This seems to be a very interesting library, but I need to dig a litte deeper and some help would be appreciated.

Thanks in advance,

Best regards,
Chris

Chris Dheere

  • Guest
Re: TF.NET - finding intersections
« Reply #6 on: February 25, 2008, 03:07:17 PM »
Hi Maksim,

can you just get me started:

i can hardly find any examples, and i get fatal errors all the time  :-(.

first thing is how to convert autocad closed polylines to TF.net polygons? i am using: Polygon pol1 = (Polygon)reader.ReadGeometry(inEnt);
my inEnt is lightweightpolyline

This gives a fatal error...

desperate Chris :-)

MaksimS

  • Guest
Re: TF.NET - finding intersections
« Reply #7 on: February 27, 2008, 11:06:05 AM »
Could you post more code related to it? What's the exception being raised? Also - writer returns non-DBRO entities and it's up to you to properly store them in DWG Database using Transaction.

You should keep in mind that LineString is _not_ a Polygon, thus typecasting won't work:

Code: [Select]
Dim reader As New DwgReader
Dim writer As New DwgWriter
Dim myLineString As LineString = reader.ReadLineString(myPolylineEntity)
Dim myLinearRing As LinearRing = reader.GeometryFactory.CreateLinearRing(myLineString.Coordinates)
Dim holes As New List(Of LinearRing)
Dim myPolygon As Polygon = reader.GeometryFactory.CreatePolygon(myLinearRing, holes.ToArray)
...
...
writer.WriteMPolygon(myPolygon)

I'm typing this without compiling, keep an eye on possible errors.

Polygon consists of LinearRings, while LinearRing can be construed from LineString is certain geometric aspects were met. Holes variable keeps possible holes (inner boundaries) found within resulting Polygon. In this example there are no holes.

Maybe you should consider using Topology.Operation.Polygonize.Polygonizer class to do the job for you. It extracts valid Polygons out of any given geometry collection. It also detects possible dangles, invalid linear rings and cut edges.

Regards,
Maksim Sestic

Hi Maksim,

can you just get me started:

i can hardly find any examples, and i get fatal errors all the time  :-(.

first thing is how to convert autocad closed polylines to TF.net polygons? i am using: Polygon pol1 = (Polygon)reader.ReadGeometry(inEnt);
my inEnt is lightweightpolyline

This gives a fatal error...

desperate Chris :-)

Chris Dheere

  • Guest
Re: TF.NET - finding intersections
« Reply #8 on: March 06, 2008, 04:37:54 PM »
Hi Maksim,

it took a little longer then I expected, but I had to finish another REAL project first. This is just hobby and learning .net :mrgreen:
i finally managed to convert my linework into Mpolygons using the polygonizer, but what i notice is that the polygonizer is not working correctly. even on a simple rectangular polyline, the resulting polygon differs in coordinates.

i must admit, it is not much (0,00002), but it is too much, especially if you want to use this in a GIS (for example on parcels).
i have tested there and the difference in area between a closed polyline (no bulges) and the polygon is a lot bigger...

have you experienced this before, or have i forgotten to specify a specific setting first?

MaksimS

  • Guest
Re: TF.NET - finding intersections
« Reply #9 on: March 07, 2008, 04:07:08 AM »
Hi Chris,

This is within expected margin of error, I'll try to explain it here. As you probably noticed, both DwgReader and DwgWriter have PrecisionModel getter property returning an object that defines precision model used during geometry conversion. API documentation states: If there's no PrecisionModel set within class constructor, returns default PrecisionModel. Default precision model is predefined FloatingSingle one.

A bit more on PrecisionModel type:
Specifies the precision model of the Coordinates in a Geometry. In other words, specifies the grid of allowable points for all Geometries. The MakePrecise method allows rounding a coordinate to a "precise" value; that is, one whose precision is known exactly. Coordinates are assumed to be precise in geometries. That is, the coordinates are assumed to be rounded to the precision model given for the point. Input routines automatically round coordinates to the precision model before creating Geometries. All internal operations assume that coordinates are rounded to the precision model. Constructive methods (such as bool operations) always round computed coordinates to the appropriate precision model.

Currently three types of precision model are supported:
Floating: represents full double precision floating point.
FloatingSingle: represents single precision floating point.
Fixed: represents a model with a fixed number of decimal places.


A Fixed Precision Model is specified by a scale factor. The scale factor specifies the grid which numbers are rounded to. Input coordinates are mapped to fixed coordinates according to the following equations: jtsPt.x = round( (inputPt.x * scale ) / scale jtsPt.y = round( (inputPt.y * scale ) / scale Coordinates are represented internally as double-precision values. Since .NET uses the IEEE-394 floating point standard, this provides 53 bits of precision. (Thus the maximum precisely representable integer is 9,007,199,254,740,992). TF.NET methods currently do not handle inputs with different precision models.

AutoCAD implications:
During conversion from IGeometry to ObjectARX entity, there's a catch with AutoCAD's internal precision representation.
I tried using full Floating support - entities do get created in DWG database - but, ACAD crashes or behaves strange on reading such entities. I already posted a sample of such "erroneous" entity here on Swamp some time ago.

You can create your own GeometryFactory using custom PrecisionModel, and use it within both DwgReader and DwgWriter.

Regards,
Maksim Sestic

MaksimS

  • Guest
Re: TF.NET - finding intersections
« Reply #10 on: March 07, 2008, 04:31:49 AM »
Chris, just a bit more (lamenting) on GIS and precision... :-)

Parcel data is kind of "static" theme in GIS. Meaning - it's measured outside of the system and then imported into CAD/GIS. People nowdays use various technologies to collect parcel data in the field, but let's consider they were collected using GPS TotalStation. Maximum precision of such geodetic instruments vary, but it's mere in a range from few millimeters to couple of centimeters. This means that surveyed point representation in AutoCAD needs 4 decimal places at most (I suppose you're using metric system). Anything more precise than that is simply a "wild guess" introduced by certain surveying data post-processing systems/applications.

Having above said in mind, even Fixed floating point PrecisionModel does the job. I mean, you can't have data output more precise than given data input - it's like a TIFF image compressed to JPG format, then have someone trying to get it back to original TIFF format without any data loss.

Regards,
Maksim Sestic


Chris Dheere

  • Guest
Re: TF.NET - finding intersections
« Reply #11 on: March 07, 2008, 11:46:32 AM »
Maksim,

I understand  but:

what I am trying to make is a routine that creates polygons from parcel data, these lines can be lines,polylines. i want to create a closed mpolygon for each parcel.
there can also be houses, that are on the edge of a parcel... it's a bit strange that after conversion, the house falls partly in the wrong parcel :-)

i can send you a little example drawing, so that you can see what happens...

another question, you told me i can make my own geometryfactory, including precisionmodel for my reader and writer.
how do i do that?how can i connect my own geometryfactory to a reader/writer?

DwgReader reader = new DwgReader();
DwgWriter writer = new DwgWriter();

PrecisionModel MyPrecModel = new PrecisionModel(PrecisionModels.Floating);
GeometryFactory MyGeomFactory = new GeometryFactory(MyPrecModel);

and then...
do you have some code?

MaksimS

  • Guest
Re: TF.NET - finding intersections
« Reply #12 on: March 12, 2008, 09:14:33 AM »
It's fixed in the SVN now, there's second constructor added to DwgReader/Writer:

Code: [Select]
Dim factory As GeometryFactory = GeometryFactory.Floating
Dim reader As New DwgReader(factory)
Dim writer As New DwgWriter(factory)

This change will be added to v1.0.9 build soon.

Regards,
Maksim Sestic