[Gdal-dev] Create Polygon in OGR / C#
Tamas Szekeres
szekerest at gmail.com
Tue Jul 24 19:13:51 EDT 2007
Jean,
You might want to test with AddGeometryDirectly instead of AddGeometry so as
to avoid the extra geometry creations.
When you have a large number of points in the rings you might want to use
the CreateFromWkb method to avoid the number of invocations between the C#/C
interface. You can create a byte array containing the wkb of the polygon in
the C# side and call the static CreateFromWkb of the Geometry class with
that array.
Currently we have no such function you have mentioned, and I'm not sure
about the proper signature to use (depending on the type of the geometry) if
needed.
Best regards,
Tamas
2007/7/24, Jean Michel PIERRET <jmp at geosys.com>:
>
> Hi,
>
>
>
> I would like transform a geometry structure in a OGR.Geometry.
>
>
>
> Struct MyGeometry
>
> {
>
> bool [] exterior = null;
>
> int [] partStarts = null;
>
> int [] partEnds = null;
>
>
>
> double [] padfX = null;
>
> double [] padfY = null;
>
> }
>
>
>
> When I use the method ExportToWkt and CreateFromWkt it's very slow.
>
> Now I have this method for the transformation :
>
>
>
> Geometry gm = null;
>
> Geometry g = null;
>
> Geometry lr = null;
>
>
>
> g = new Geometry(wkbGeometryType.wkbPolygon);
>
>
>
> for (int i = 0; i < partStarts.Length; i++)
>
> {
>
> if (exterior[i])
>
> {
>
> if (i > 0)
>
> {
>
> if (gm == null)
>
> gm = new Geometry(wkbGeometryType.wkbMultiPolygon
> );
>
> gm.AddGeometry(g);
>
> g.Dispose();
>
> g = null;
>
> }
>
>
>
> if (g == null)
>
> g = new Geometry(wkbGeometryType.wkbPolygon);
>
> }
>
>
>
> lr = new Geometry(wkbGeometryType.wkbLinearRing);
>
> for (int j = partStarts[i]; j < partEnds[i]; j++)
>
> lr.AddPoint(padfX[j], padfY[j], 0);
>
>
>
> g.AddGeometry(lr);
>
> lr.Dispose();
>
> lr = null;
>
> }
>
>
>
> if (gm != null)
>
> {
>
> if (g != null)
>
> {
>
> gm.AddGeometry(g);
>
> g.Dispose();
>
> g = null;
>
> }
>
>
>
> return gm;
>
> }
>
> else
>
> return g;
>
>
>
> It works but it is not very quick, It's possible to have a function like
> in the shapelib
>
>
>
> SHPObject SHPCreateObject(ShapeType shpType, int nShapeId, int nParts, int[]
> panPartStart, PartType[] paPartType, int nVertices, double[] adfX, double[]
> adfY, double[] adfZ, double[] adfM);
>
>
>
> Thanks for your support.
>
>
>
> Best Regards.
>
>
>
>
>
> *Jean-michel PIERRET <jmp at geosys.com> - Poste 376*
>
> *Tel : +33 (0)5 62 47 80 76*
> *Mail* : jmp at geosys.com
> *GEOSYS SA*
>
>
>
>
>
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20070725/cace8177/attachment.html
More information about the Gdal-dev
mailing list