[Gdal-dev] Writing a polygon to a new shapefile

AmandaH amanda.m.henneke at boeing.com
Tue Mar 24 13:09:06 EDT 2009


Hello-

I'm new to the GDAL/OGR libraries.  I'm trying to use the C# wrapper to OGR in order to create a new shapefile, but I'm running into some issues.  Here is the code I have...can anyone tell me what I'm doing wrong?

Geometry temp_geom;

OSGeo.OGR.Driver new_drv = Ogr.GetDriverByName("ESRI Shapefile");
OSGeo.OGR.SpatialReference new_sr = new OSGeo.OGR.SpatialReference("");
OSGeo.OGR.DataSource ds_out = new_drv.CreateDataSource("D:\\Vector\\Output\\new.shp", new string[] { });

new_sr.IsSameGeogCS(old_sr);

OSGeo.OGR.Layer new_layer = ds_out.CreateLayer("new_polygons", new_sr,   OSGeo.OGR.wkbGeometryType.wkbPolygon, new string[] { });
               
FeatureDefn new_def = new_layer.GetLayerDefn();
OSGeo.OGR.Feature new_feat = new OSGeo.OGR.Feature(new_def);

temp_geom = new Geometry(wkbGeometryType.wkbPolygon);

dX = geom.GetX(iPoint);
dY = geom.GetY(iPoint);
dZ = geom.GetZ(iPoint);

temp_geom.AddPoint(dX, dY, dZ);

new_feat.SetGeometryDirectly(temp_geom);
new_layer.CreateFeature(new_feat);
temp_geom.Dispose();

-- 
View this message in context: http://n2.nabble.com/Writing-a-polygon-to-a-new-shapefile-tp2527864p2527864.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.



More information about the gdal-dev mailing list