/// <summary> /// Converts the geometry to WKB. /// </summary> /// <param name="geometry">The geometry</param> /// <returns>WKB byte array</returns> private static byte[] ConvertGeometryToWKB(IGeometry geometry) { IWkb wkb = geometry as IWkb; ITopologicalOperator oper = geometry as ITopologicalOperator; oper.Simplify(); IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3; byte[] b = factory.CreateWkbVariantFromGeometry(geometry) as byte[]; return(b); }
public void Export(ILayer layer, OIDList oids, int srid, int commitinterval) { IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3; IFeatureLayer featureLayer = (IFeatureLayer)layer; IDataset dataset = (IDataset)featureLayer.FeatureClass; GeoDataTableAdapter.GeoAdapter adapter = new GeoDataTableAdapter.GeoAdapter(dataset.Workspace); this.CommitInterval = commitinterval; int i = 0; string tableName = layer.Name.Replace(' ', '_'); while (i < oids.Count) { int elementcount; if (i + this.CommitInterval > oids.Count) { elementcount = oids.Count - i; } else { elementcount = this.CommitInterval; } OIDList oidrange = oids.GetRange(i, elementcount); object[] vals = oidrange.ToObjectArray(); DataTable table = adapter.GetAttributeTable(dataset.Name, featureLayer.FeatureClass.OIDFieldName, vals); table.AddWKBColumn(); foreach (DataRow row in table.Rows) { int oid = Convert.ToInt32(row[featureLayer.FeatureClass.OIDFieldName]); IFeature feature = featureLayer.FeatureClass.GetFeature(oid); byte[] wkbgeometry = (byte[])factory.CreateWkbVariantFromGeometry(feature.ShapeCopy); row["WKB"] = wkbgeometry; } Write(table, tableName, srid, featureLayer.FeatureClass); i += this.CommitInterval; } }
/// <summary> /// 将ArcGIS中的Geometry转换成wkb /// </summary> /// <param name="geometry">ArcGIS中的Geometry对象</param> /// <returns></returns> public static byte[] ConvertGeometryToWkb(IGeometry geometry) { var wkb = geometry as IWkb; ITopologicalOperator oper = geometry as ITopologicalOperator; if (oper != null) { oper.Simplify(); } IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3; if (factory != null) { byte[] b = factory.CreateWkbVariantFromGeometry(geometry) as byte[]; return(b); } return(null); }
public void Export(string spatialiteDatabasePath, int srid, ILayer layer) { try { this.DatabasePath = spatialiteDatabasePath; if (srid > 0) { IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3; IFeatureLayer featureLayer = (IFeatureLayer)layer; IDataset dataset = (IDataset)featureLayer.FeatureClass; GeoDataTableAdapter.GeoAdapter adapter = new GeoDataTableAdapter.GeoAdapter(dataset.Workspace); DataTable table = null; ITable featureTable = (ITable)featureLayer.FeatureClass; if (this.Extent != null) { ISpatialFilter filter = new SpatialFilterClass(); filter.Geometry = this.Extent; filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; filter.SubFields = featureLayer.FeatureClass.OIDFieldName; IFeatureCursor cursor = featureLayer.FeatureClass.Search(filter, true); IFeature feature = null; object[] vals = new object[featureLayer.FeatureClass.FeatureCount(filter)]; int w = 0; while ((feature = cursor.NextFeature()) != null) { vals[w++] = feature.OID; } table = adapter.GetAttributeTable(dataset.Name, featureLayer.FeatureClass.OIDFieldName, vals); } else { // no events for the adapter, so just 1 step for now. // TODO: update GeoDataTableAdapter w/ events. this.OnAttributeReadProgress(0, 1); table = adapter.GetAttributeTable(featureTable, dataset.Name.Replace('.', '_')); this.OnAttributeReadProgress(1, 1); } DataColumn wkbcolumn = new DataColumn("WKB", typeof(byte[])); table.Columns.Add(wkbcolumn); int totalRows = table.Rows.Count; int i = 0; this.OnGeometryReadProgress(i, totalRows); foreach (DataRow row in table.Rows) { this.OnGeometryReadProgress(++i, totalRows); int oid = Convert.ToInt32(row[featureLayer.FeatureClass.OIDFieldName]); IFeature feature = featureLayer.FeatureClass.GetFeature(oid); byte[] wkbgeometry = (byte[])factory.CreateWkbVariantFromGeometry(feature.ShapeCopy); row["WKB"] = wkbgeometry; } WriteTable(this.SpatialiteDatabase, srid, table, featureLayer.FeatureClass); } else { } // this.SpatialiteDatabase.Close(); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.StackTrace); throw; } }