ESRI ArcObjects Geometry to NTS Geometry

255 views
Skip to first unread message

Sanjay

unread,
Oct 17, 2011, 2:54:32 AM10/17/11
to NetTopologySuite
Hello,

Is there a way in NTS to convert an ArcObjects Geometry object to NTS
Geometry?
I have tried various examples off the net e.g.

http://code.google.com/p/dylansknowledgebase/source/browse/trunk/spatial/Spatial.Formats/Spatial.Formats/Converters.cs

I am getting the error "Array out of bounds" error at run-time at the
following line:
var b = _geometryFactory.CreateWkbVariantFromGeometry(geometry) as
byte[];

I am using ArcGIS 10 and VSE2008.

Anyone came across this error before?

Thanks,
Sanjay.





GIS Geezer

unread,
Oct 17, 2011, 11:44:24 AM10/17/11
to NetTopologySuite
Sanjay

I've used a version of this code recently to convert both from and to
esri geometry with no problems. It sounds like it may be a problem
with a specific geometry you are trying to convert. Have you checked
the geometry is valid prior to converting to NTS? For example, are you
testing for null geometry?

One other thing to mention is that esri (especially sde) is quite
fussy about having valid geometry - so if you are converting TO esri
geometry with this code you should ideally, immediately after
conversion:

1) set the spatial reference (including coordinate resolution/
tolerance) to match the target feature class;
2) set IsKnownSimple for the geometry to FALSE and then perform an
ITopologicalOperator.Simplify().

Otherwise you may get geometry errors reported by esri.

John

GIS4Business
http://www.gis4business.co.uk


On Oct 17, 7:54 am, Sanjay <sanjayrana2...@gmail.com> wrote:
> Hello,
>
> Is there a way in NTS to convert an ArcObjects Geometry object to NTS
> Geometry?
> I have tried various examples off the net e.g.
>
> http://code.google.com/p/dylansknowledgebase/source/browse/trunk/spat...

Sanjay

unread,
Oct 18, 2011, 2:44:23 AM10/18/11
to NetTopologySuite
John

Thanks for picking up the post. I think I have a vague idea of the
source of the problem but I don't really know why it might be
happening.

I had the conversion code inside a backgroundworker thread. I was
passing the IFeatureLayer to the backgroundworker thread.
Using the IFeatureLayer, I was able to read the feature class and the
geometry inside the featureclass but got the error when trying to
convert the ESRI geometry to OGC.
I have a suspicion that this might be due to IGeometryFactory or
GeometryEnvironment being out of scope inside the backgroundworker but
that could be all nonsense logic..

So, I basically moved the conversion out of the backgroundworker and
it appears to be working okay for now..

Sanjay


On Oct 17, 4:44 pm, GIS Geezer <john.fan...@gis4business.co.uk> wrote:
> Sanjay
>
> I've used a version of this code recently to convert both from and to
> esri geometry with no problems. It sounds like it may be a problem
> with a specific geometry you are trying to convert. Have you checked
> the geometry is valid prior to converting to NTS? For example, are you
> testing for null geometry?
>
> One other thing to mention is that esri (especially sde) is quite
> fussy about having valid geometry - so if you are converting TO esri
> geometry with this code you should ideally, immediately after
> conversion:
>
> 1) set the spatial reference (including coordinate resolution/
> tolerance) to match the target feature class;
> 2) set IsKnownSimple for the geometry to FALSE and then perform an
> ITopologicalOperator.Simplify().
>
> Otherwise you may get geometry errors reported by esri.
>
> John
>
> GIS4Businesshttp://www.gis4business.co.uk
Reply all
Reply to author
Forward
0 new messages