private void _load(bool leaveopen = false) { Open(); // Populate some important metadata Layer mLayer = _ds.GetLayerByIndex(0); FIDColumn = mLayer.GetFIDColumn(); LayerName = mLayer.GetName(); _geometryType = new GDalGeometryType(mLayer.GetGeomType()); // Get our FEATURE definitions Feature mFeat = mLayer.GetNextFeature(); while (mFeat != null) { Geometry geo = mFeat.GetGeometryRef(); if (geo == null) { Debug.WriteLine(String.Format("Warning: Null Geometry Detected: FID:{0}", mFeat.GetFID())); } else { int count = geo.GetGeometryCount(); if (count > 1) { if (_geometryType.SimpleType == SimpleTypes.Point || _geometryType.SimpleType == SimpleTypes.LineString) { Exception ex = new Exception("Multi-part geometries are detected in this file. This is not allowed."); ex.Data["File Path"] = GISFileInfo.FullName; ex.Data["Solution"] = "Remove all multipart features from this ShapeFile."; throw ex; } else { Debug.WriteLine(String.Format("Warning: Multipart feature detected: FID:{0}", mFeat.GetFID())); } } } Features.Add(mFeat.GetFID(), new VectorFeature(mFeat)); mFeat = mLayer.GetNextFeature(); } // Now get our FIELD definitions FeatureDefn mFeatDfn = mLayer.GetLayerDefn(); int iFldCnt = mFeatDfn.GetFieldCount(); for (int fldId = 0; fldId < iFldCnt; fldId++) { FieldDefn mFldDef = mFeatDfn.GetFieldDefn(fldId); Fields.Add(mFldDef.GetName(), new VectorField(mFldDef, fldId)); } // Spatial is way harder than it needs to be: OSGeo.OSR.SpatialReference sRef = mLayer.GetSpatialRef(); if (sRef == null) { Exception ex = new Exception("Feature class is missing spatial reference"); ex.Data["Path"] = GISFileInfo.FullName; throw ex; } string sRefstring = ""; sRef.ExportToWkt(out sRefstring); _Init(sRefstring); if (!leaveopen) { UnloadDS(); } }
public GDalGeometryType(GDalGeometryType origGType) { _origType = origGType._origType; }