public IExtents GetExtentsByOid(TOid oid) { FeatureQueryExpression query = new FeatureQueryExpression(new AttributesProjectionExpression(new[] { GeometryColumn }), null, null, new OidCollectionExpression(new[] { oid }), null); using (IFeatureDataReader fdr = ExecuteFeatureQuery(query)) { while (fdr.Read()) { return((IExtents)fdr.Geometry.Extents.Clone()); } } return(GeometryFactory.CreateExtents()); }
public void TestGeometryProvider() { string wkt; GeometryServices g = new GeometryServices(); GeometryProvider prov; IGeometry geom = g.DefaultGeometryFactory.WktReader.Read(File.ReadAllText("D:\\geometries.txt")); prov = new GeometryProvider(new[] { geom }); using (IFeatureDataReader fdr = prov.ExecuteFeatureQuery(new FeatureQueryExpression(geom.Extents, SpatialOperation.Intersects))) { while (fdr.Read()) { Debug.WriteLine(fdr.Geometry.AsText()); } } }
private void Export(string colName) { ExportDirectory = Path.Combine(Path.GetDirectoryName(Provider.Filename), Path.GetFileNameWithoutExtension(Provider.Filename) + "_Export"); if (!Directory.Exists(ExportDirectory)) { Directory.CreateDirectory(ExportDirectory); } FeatureDataTable fdt = Provider.CreateNewTable(); IFeatureDataReader reader = Provider.GetReader(); while (reader.Read()) { string layerName = GenerateUniqueName(reader[colName].ToString()); using ( ShapeFileProvider export = ShapeFileProvider.Create(ExportDirectory, layerName, Provider.ShapeType, Provider.CreateNewTable(), Provider.GeometryFactory, _geometryServices.CoordinateSystemFactory)) { export.IsSpatiallyIndexed = false; export.Open(); FeatureDataRow <uint> fdr = (FeatureDataRow <uint>)fdt.NewRow(); object[] vals = new object[fdt.Columns.Count]; reader.GetValues(vals); fdr.ItemArray = vals; fdr.Geometry = reader.Geometry; export.Insert(fdr); export.Close(); } } }
private void btnExecute_Click(object sender, EventArgs e) { if (m_dsProvider != null) { dgvResults.Rows.Clear(); try { // Comment the following line for versions less or equal v. 2.2 IExpressionEvaluationContext exprEvalContext = new DefaultExpressionEvaluationContext(); IFeatureExpressionFilter filterExpr = null; if (txtFilter.Text.Trim() != string.Empty) { filterExpr = new FeatureExpressionFilter(); filterExpr.Compile(txtFilter.Text, m_dsProvider.Information.Attributes); } Envelope env = m_dsProvider.GetExtent(); List <string> properties = m_dsProvider.Information.GetAttributeNames(); properties.Remove("_geom_"); DataSourceQuery query = new DataSourceQuery(env, new Tuple <double, double>(1.0, 1.0), null, null, properties); IFeatureDataReader dataReader = m_dsProvider.GetFeatureReader(query, FeatureFactory.Default); int i = 0; if (dataReader != null) { int rowsLimit = (int)nudRowsLimit.Value; while (dataReader.Read()) { Feature feature = dataReader.GetFeature(); if (rowsLimit > 0 && i >= rowsLimit) { break; } bool bFeaturePass = true; if (filterExpr != null) { // Apply a given expression to filter features from the data source. // Change the following line for versions less or equal v. 2.2 by replacing the expression with filterExpr.Pass(feature) bFeaturePass = filterExpr.Pass(feature, exprEvalContext); } if (bFeaturePass) { DataGridViewRow row = (DataGridViewRow)dgvResults.Rows[0].Clone(); object[] values = new object[feature.Attributes.Count]; int j = 0; // Enumerate feature properties and fill the grid view. foreach (string attr in feature.Attributes.EnumerateNames()) { object value = feature.GetPropertyValue(attr); if (attr == "_geom_") { value = value.ToString().Replace("MapSurfer.Geometries.", ""); } values[j] = value; row.Cells[j].Value = value; j++; } row.SetValues(values); dgvResults.Rows.Add(row); i++; } } DisposeUtility.Dispose(ref dataReader); } lblRows.Text = i.ToString() + " rows"; UpdateMessage(string.Format("{0} row(s) fetched.", i)); } catch (Exception ex) { UpdateMessage("Exception: " + ex.Message); } } }