[Gdal-dev] Create Polygon in OGR / C#

Frank Warmerdam warmerdam at pobox.com
Wed Jul 25 21:52:01 EDT 2007


Jean Michel PIERRET wrote:
> 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);

Jean-michel,

I'm not sure I'd want an all in one function like SHPCreateObject(), but
I think it would be helpful (and easy) to add an AddPoints() or SetPoints()
method for line strings to add a whole array of points in one step.  That
would likely help a lot.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org




More information about the Gdal-dev mailing list