public Task <IFeature> NextFeature() { if (_layer == null) { return(Task.FromResult <IFeature>(null)); } OSGeo_v3.OGR.Feature ogrfeature = _layer.GetNextFeature(); if (ogrfeature == null) { return(Task.FromResult <IFeature>(null)); } Feature feature = new Feature(); feature.OID = (int)ogrfeature.GetFID(); OSGeo_v3.OGR.FeatureDefn defn = ogrfeature.GetDefnRef(); int fieldCount = defn.GetFieldCount(); for (int i = 0; i < fieldCount; i++) { OSGeo_v3.OGR.FieldDefn fdefn = defn.GetFieldDefn(i); FieldValue fv = new FieldValue(fdefn.GetName()); string fieldType = fdefn.GetFieldTypeName(fdefn.GetFieldType()).ToLower(); switch (fieldType) { case "integer": fv.Value = ogrfeature.GetFieldAsInteger(i); break; case "real": fv.Value = ogrfeature.GetFieldAsDouble(i); break; default: fv.Value = ogrfeature.GetFieldAsString(i); break; } feature.Fields.Add(fv); } if (feature.Shape == null) { OSGeo_v3.OGR.Geometry geom = ogrfeature.GetGeometryRef(); if (geom != null) { byte[] buffer = new byte[geom.WkbSize()]; geom.ExportToWkb(buffer); feature.Shape = gView.Framework.OGC.OGC.WKBToGeometry(buffer); } } return(Task.FromResult <IFeature>(feature)); }
public FeatureClassV3(Dataset dataset, string name) { _dataset = dataset; _name = name; using (var dataSource = OSGeo_v3.OGR.Ogr.Open(_dataset.ConnectionString, 0)) using (var ogrLayer = dataSource.GetLayerByName(_name)) { OSGeo_v3.OGR.FeatureDefn defn = ogrLayer.GetLayerDefn(); _name = defn.GetName(); if (dataset.ConnectionString.ToLower().EndsWith(".dxf")) { try { System.IO.FileInfo fi = new System.IO.FileInfo(dataset.ConnectionString); _name = fi.Name; } catch { } } _fields = new Fields(); for (int i = 0; i < defn.GetFieldCount(); i++) { OSGeo_v3.OGR.FieldDefn fdefn = defn.GetFieldDefn(i); Field field = new Field(fdefn.GetName()); switch (fdefn.GetFieldTypeName(fdefn.GetFieldType()).ToLower()) { case "integer": if (_idFieldName == String.Empty) { _idFieldName = field.name; } field.type = FieldType.integer; break; case "real": field.type = FieldType.Double; break; case "string": field.type = FieldType.String; field.size = fdefn.GetWidth(); break; } _fields.Add(field); } using (var spatialRef = defn.GetGeomFieldDefn(0)?.GetSpatialRef()) { if (spatialRef != null) { string proj4; spatialRef.ExportToProj4(out proj4); if (!String.IsNullOrEmpty(proj4)) { var sRef = new SpatialReference(spatialRef.GetName()); sRef.Parameters = proj4.Split(' '); this.SpatialReference = sRef; } } } _countFeatures = ogrLayer.GetFeatureCount(1); OSGeo_v3.OGR.Envelope env = new OSGeo_v3.OGR.Envelope(); ogrLayer.GetExtent(env, 1); _envelope = new Envelope(env.MinX, env.MinY, env.MaxX, env.MaxY); switch (defn.GetGeomType()) { case OSGeo_v3.OGR.wkbGeometryType.wkbPoint: _geomType = geometryType.Point; break; case OSGeo_v3.OGR.wkbGeometryType.wkbLineString: case OSGeo_v3.OGR.wkbGeometryType.wkbMultiLineString: _geomType = geometryType.Polyline; break; case OSGeo_v3.OGR.wkbGeometryType.wkbPolygon: case OSGeo_v3.OGR.wkbGeometryType.wkbMultiPolygon: _geomType = geometryType.Polygon; break; } } }