本文整理汇总了C#中SharpMap.Data.FeatureDataSet类的典型用法代码示例。如果您正苦于以下问题:C# FeatureDataSet类的具体用法?C# FeatureDataSet怎么用?C# FeatureDataSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FeatureDataSet类属于SharpMap.Data命名空间,在下文中一共展示了FeatureDataSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCreateFromFeatureDataTable
public void TestCreateFromFeatureDataTable()
{
var fds = new SharpMap.Data.FeatureDataSet();
FeatureDataTable fdt = null;
try
{
var p = new Ogr("C:\\Users\\obe.IVV-AACHEN\\Downloads\\SharpMap Codeplex\\SHPFiles\\RxLevel-Idle.shp");
p.SRID = 4326;
var layer = string.Empty;
if (!string.IsNullOrEmpty(layer)) p.LayerName = layer;
p.ExecuteIntersectionQuery(p.GetExtents(), fds);
fdt = fds.Tables[0];
if (fdt.Rows.Count == 0)
throw new Exception("no data in layer");
}
catch (Exception ex)
{
throw new IgnoreException("Getting data failed", ex);
}
Assert.DoesNotThrow(() => Ogr.CreateFromFeatureDataTable(fdt,
((FeatureDataRow)fdt.Rows[0]).Geometry.OgcGeometryType, 4326,
"Mapinfo File",
"C:\\Users\\obe.IVV-AACHEN\\Downloads\\SharpMap Codeplex\\SHPFiles\\RxLevel-Idle.tab"));
}
示例2: FindGeoNearPoint
public static FeatureDataRow FindGeoNearPoint(GeoAPI.Geometries.IPoint point, VectorLayer layer, double amountGrow)
{
var box = new Envelope(point.Coordinate);
box.ExpandBy(amountGrow);
var fds = new FeatureDataSet();
layer.DataSource.ExecuteIntersectionQuery(box, fds);
FeatureDataRow result = null;
var minDistance = double.MaxValue;
foreach (FeatureDataTable fdt in fds.Tables)
{
foreach (FeatureDataRow fdr in fdt.Rows)
{
if (fdr.Geometry != null)
{
var distance = point.Distance(fdr.Geometry);
if (distance < minDistance)
{
result = fdr;
minDistance = distance;
}
}
}
}
return result;
}
示例3: render2d
public void render2d(Project project, PictureBox picBox)
{
SharpMap.Map myMap = new SharpMap.Map();
foreach (BuildLayer layer in project.getLayers())
{
Source source = layer.getSource();
BoundingBox envelope = new BoundingBox(-1000.0, -1000.0, 1000.0, 1000.0);//TODO
FeatureDataSet ds = new FeatureDataSet();
source.DataSource.Open();
source.DataSource.ExecuteIntersectionQuery(envelope, ds);
source.DataSource.Close();
FeatureDataTable features = (FeatureDataTable)ds.Tables[0];
string label = "Trace test:\n";
foreach (FeatureDataRow row in features)
{
foreach (Object item in row.ItemArray)
label += " - " + item;
label += "\n";
}
setLabel(label);
//Show map
//Filters
FilterGraph graph = project.getFilterGraph(source.getName());
if (graph != null)
{
foreach (FeatureFilter filter in graph.getFilters())
{
//aplicar filtro segun el tipo
Mogre.DefaultSceneManagerFactory dsmf = new DefaultSceneManagerFactory();
Mogre.SceneManager sm = dsmf.CreateInstance("scenemanager");
FilterEnv env = new FilterEnv(sm, "env");
foreach (MogreGis.Resource resource in project.getResources())
{
env.getSession().Resources.addResource(resource);
}
FeatureList list = Feature.DataTableToList(features);
filter.process(list, env);
//falta devolver la lista y procesarla ***************************************
}
}
SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer(layer.getName());
myLayer.DataSource = source.DataSource;
myMap.Layers.Add(myLayer);
}
myMap.Size = new Size(picBox.Width, picBox.Height);
myMap.ZoomToExtents();
picBox.Image = myMap.GetMap();
this.map = myMap;
}
示例4: ExecuteFeatureReader
public IFeatureReader ExecuteFeatureReader(SpatialPredicate predicate, Envelope envelope)
{
if (predicate != SpatialPredicate.Intersects)
throw new NotSupportedException();
var fds = new FeatureDataSet();
_provider.ExecuteIntersectionQuery(envelope, fds);
return new ProviderFeatureDataRowReader(fds.Tables[0]);
}
示例5: TestExecuteIntersectionQueryAgainstEnvelope
public void TestExecuteIntersectionQueryAgainstEnvelope()
{
using (var p = CreateProvider())
{
var fds = new FeatureDataSet();
Assert.DoesNotThrow(() => p.ExecuteIntersectionQuery(p.GetExtents(), fds));
Assert.AreEqual(1, fds.Tables.Count);
var table = fds.Tables[0];
Assert.AreEqual(_tableName, table.TableName);
Assert.AreEqual(4, table.Rows.Count);
}
}
示例6: TestIndexing
public void TestIndexing()
{
var fds = new FeatureDataSet { DataSetName = "Indexing" };
var ds = (DataSet)fds;
for (var i = 0; i < 10; i++)
ds.Tables.Add(i%2 == 0 ? CreateFeatureDataTable("T" + i) : CreateDataTable("T" + i, true));
Assert.AreEqual(10, ds.Tables.Count);
Assert.AreEqual(5, fds.Tables.Count);
for (var i = 0; i < 5; i++)
Assert.IsTrue(ReferenceEquals(ds.Tables[2*i], fds.Tables[i]));
}
示例7: GetData
public JsonResult GetData(float w, float n, float e, float s, int z)
{
string format = String.Format("~/App_Data/berlin/{0}", "osmbuildings.shp");
string path = this.HttpContext.Server.MapPath(format);
if (!System.IO.File.Exists(path))
throw new FileNotFoundException("file not found", path);
Point start = this.GeoToPixel(n, w, z);
var meta = new { n, w, s, e, x = start.X, y = start.Y, z };
Envelope bbox = new Envelope();
bbox.ExpandToInclude(new Coordinate(n, w));
bbox.ExpandToInclude(new Coordinate(s, e));
FeatureDataSet ds = new FeatureDataSet();
using (ShapeFile provider = new ShapeFile(path))
{
provider.DoTrueIntersectionQuery = true;
provider.Open();
provider.ExecuteIntersectionQuery(bbox, ds);
provider.Close();
}
int zz = MaxZoom - z;
List<object> data = new List<object>();
FeatureDataTable table = ds.Tables[0];
foreach (FeatureDataRow row in table)
{
int c = (short)(row["height"]);
if (c == 0)
c = 5; // default value for "null" (zero) heights
int h = c * ScaleZ >> zz;
if (h <= 1)
h = 1;
IGeometry geometry = row.Geometry;
Coordinate[] coords = geometry.Coordinates;
int total = coords.Length;
double[] values = new double[total * 2];
int i = 0;
foreach (Coordinate curr in coords)
{
Point p = this.GeoToPixel(curr.X, curr.Y, z);
values[i++] = p.X - start.X;
values[i++] = p.Y - start.Y;
}
data.Add(new object[] { h, values });
}
return this.Json(new { meta, data }, JsonRequestBehavior.AllowGet);
}
示例8: TestSerializationOfDataset
public void TestSerializationOfDataset()
{
var fds = new FeatureDataSet { DataSetName = "Serialization", Namespace = "ns" };
using (var p = Serialization.ProviderTest.CreateProvider("managedspatialite"))
{
p.Open();
p.ExecuteIntersectionQuery(p.GetExtents(), fds);
p.Close();
}
// add second datatable for multi-layer queries
var l2 = CreateFeatureDataTable("layer 2");
l2.ExtendedProperties.Add("dummy", 5);
fds.Tables.Add(l2);
// add second datatable and relation
var l3 = CreateFeatureDataTable("layer 3");
fds.Tables.Add(l3);
fds.Relations.Add(l2.Columns["oid"], l3.Columns["oid"]);
FeatureDataSet deserializedFds = null;
Assert.DoesNotThrow(() => deserializedFds = SandD(fds, GetFormatter()));
Assert.That(deserializedFds.Namespace, Is.EqualTo(fds.Namespace));
Assert.That(deserializedFds.DataSetName, Is.EqualTo(fds.DataSetName));
Assert.That(deserializedFds.Locale, Is.EqualTo(fds.Locale));
Assert.That(deserializedFds.EnforceConstraints, Is.EqualTo(fds.EnforceConstraints));
Assert.That(deserializedFds.Prefix, Is.EqualTo(fds.Prefix));
Assert.That(deserializedFds.Tables.Count, Is.EqualTo(fds.Tables.Count));
var deserializedLayer2Table = deserializedFds.Tables.First(fdt => fdt.TableName == "layer 2");
var deserializedLayer3Table = deserializedFds.Tables.First(fdt => fdt.TableName == "layer 3");
Assert.That(deserializedLayer2Table.ExtendedProperties.ContainsKey("dummy"),
"DataSet.ExtendedProperties not serialized");
Assert.That(deserializedLayer2Table.ExtendedProperties.ContainsValue("5"));
Assert.That(deserializedFds.Relations.Count, Is.EqualTo(1), "Relations not serialized");
Assert.That(deserializedFds.Relations[0].ParentTable, Is.EqualTo(deserializedLayer2Table), "Wrong parent relation");
Assert.That(deserializedFds.Relations[0].ChildTable, Is.EqualTo(deserializedLayer3Table), "Wrong child relation");
Assert.That(deserializedLayer2Table.Constraints.Count, Is.EqualTo(1), "Constraints not serialized");
var cons = deserializedLayer2Table.Constraints[0] as UniqueConstraint;
Assert.NotNull(cons, "Wrong contraint");
Assert.IsTrue(cons.IsPrimaryKey, "Constraint was a primary key");
}
示例9: TestQuery
public void TestQuery()
{
var p =
new SharpMap.Data.Providers.WFS("http://geo.vliz.be/geoserver/wfs?service=WFS&request=GetCapabilities",
"nsTmp", "elevation_10m", SharpMap.Data.Providers.WFS.WFSVersionEnum.WFS1_1_0);
p.FeatureTypeInfo.Geometry._GeometryName = "the_geom";
//p.FeatureTypeInfo.Geometry._GeometryType =
var ext = p.GetExtents();
var g = p.GetGeometriesInView(new GeoAPI.Geometries.Envelope(-90, 90, -180, 180));
Assert.That(g.Count > 0);
var fds = new FeatureDataSet();
Assert.DoesNotThrow(() => p.ExecuteIntersectionQuery(p.GetExtents(), fds));
}
示例10: TestCreateJoin
public void TestCreateJoin()
{
var fds = new FeatureDataSet {DataSetName = "Join"};
var ds = (DataSet) fds;
var t1 = CreateFeatureDataTable("T1");
fds.Tables.Add(t1);
Assert.AreEqual(1, ((DataSet)fds).Tables.Count);
var t2 = CreateDataTable("T2");
ds.Tables.Add(t2);
Assert.AreEqual(2, ds.Tables.Count);
Assert.AreEqual(1, fds.Tables.Count);
Assert.DoesNotThrow( () => fds.Relations.Add(t1.Columns[0], t2.Columns[0]));
}
示例11: GetIntersectingFeaturesUsingFilterDelegate
/// <summary>
/// This method returns a FeatureDataTable containing all the rows from the shapefile that intersect the testGeometry.
/// The ShapeFile.ExecuteIntersectionQuery method only tests bounding boxes so we use the FilterDelegate property to add a true
/// intersection test using NetTopologySuite
/// </summary>
/// <param name="pathToShapefile">The path to the shapefile</param>
/// <param name="testGeometry">The geometry that we want to test against</param>
/// <returns></returns>
public FeatureDataTable GetIntersectingFeaturesUsingFilterDelegate(string pathToShapefile, Geometry testGeometry)
{
//create a new shapefile provider
using (ShapeFile shapefile = new ShapeFile(pathToShapefile))
{
//create an nts GeometryFactory
GeometryFactory geometryFactory = new GeometryFactory();
//convert the testGeometry into the equivalent NTS geometry
GeoAPI.Geometries.IGeometry testGeometryAsNtsGeom = GeometryConverter.ToNTSGeometry(testGeometry, geometryFactory);
Geometry check = GeometryConverter.ToSharpMapGeometry(testGeometryAsNtsGeom);
if (!check.Equals(testGeometry))
throw new ApplicationException("conversion error");
//set the shapefile providers' FilterDelegate property to a new anonymous method
//this delegate method will be called for each potential row
shapefile.FilterDelegate = delegate(FeatureDataRow featureDataRow)
{
//get the geometry from the featureDataRow
Geometry rowGeometry = featureDataRow.Geometry;
//convert it to the equivalent NTS geometry
GeoAPI.Geometries.IGeometry compareGeometryAsNtsGeometry =
GeometryConverter.ToNTSGeometry(rowGeometry, geometryFactory);
//do the test. Note that the testGeometryAsNtsGeometry is available here because it is
//declared in the same scope as the anonymous method.
bool intersects =
testGeometryAsNtsGeom.Intersects(compareGeometryAsNtsGeometry);
//return the result
return intersects;
};
//create a new FeatureDataSet
FeatureDataSet featureDataSet = new FeatureDataSet();
//open the shapefile
shapefile.Open();
//call ExecuteIntersectionQuery. The FilterDelegate will be used to limit the result set
shapefile.ExecuteIntersectionQuery(testGeometry, featureDataSet);
//close the shapefile
shapefile.Close();
//return the populated FeatureDataTable
return featureDataSet.Tables[0];
}
}
示例12: TestProvider
private static void TestProvider(IProvider provider, GpkgContent content)
{
int numFeatures = 0;
Assert.DoesNotThrow(() => numFeatures = provider.GetFeatureCount(),
"GetFeatureCount threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
var extent = provider.GetExtents();
Collection<uint> oids = null;
Assert.DoesNotThrow(() => oids = provider.GetObjectIDsInView(extent),
"GetObjectIDsInView threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
Assert.AreEqual(numFeatures, oids.Count);
foreach (var oid in oids)
{
IGeometry geom = null;
Assert.DoesNotThrow(() => geom = provider.GetGeometryByID(oid),
"GetGeometryByID threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
FeatureDataRow feat = null;
Assert.DoesNotThrow(() => feat = provider.GetFeature(oid),
"GetFeature threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
Assert.IsTrue(geom.EqualsExact(feat.Geometry));
}
Collection<IGeometry> geoms = null;
Assert.DoesNotThrow(() => geoms = provider.GetGeometriesInView(extent),
"GetFeature threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
Assert.AreEqual(numFeatures, geoms.Count);
var fds = new FeatureDataSet();
Assert.DoesNotThrow(() => provider.ExecuteIntersectionQuery(extent, fds),
"GetFeature threw exception:\n\tConnection{0}\n\t{1}",
provider.ConnectionID, content.TableName);
Assert.AreEqual(numFeatures, fds.Tables[0].Rows.Count);
}
示例13: TestExecuteIntersectionQueryAgainstEnvelopeEqualsGetOidsInView
public void TestExecuteIntersectionQueryAgainstEnvelopeEqualsGetOidsInView()
{
using (var p = CreateProvider())
{
var ext =p.GetExtents();
var fds = new FeatureDataSet();
Assert.DoesNotThrow(() => p.ExecuteIntersectionQuery(ext, fds));
Assert.AreEqual(1, fds.Tables.Count);
var table = fds.Tables[0];
Assert.AreEqual(_tableName, table.TableName);
Assert.AreEqual(4, table.Rows.Count);
var oids = p.GetObjectIDsInView(ext);
Assert.AreEqual(table.Rows.Count, oids.Count);
foreach (FeatureDataRow row in table.Select())
Assert.IsTrue(oids.Contains((uint)(int)row[0]));
}
}
示例14: ExecuteIntersectionQueryReturnsExpectedFeatures
public void ExecuteIntersectionQueryReturnsExpectedFeatures()
{
DataTable source = CreateDataTableSource();
DataTablePoint provider = new DataTablePoint(source, "oid", "x", "y");
var query = new Envelope(400, 600, 400, 600);
FeatureDataTable expected = new FeatureDataTable();
expected.TableName = "PointSource";
foreach (DataColumn column in source.Columns)
{
expected.Columns.Add(column.ColumnName, column.DataType);
}
foreach (DataRowView rowView in source.DefaultView)
{
if (query.Contains(new Coordinate((double) rowView["x"], (double) rowView["y"])))
{
expected.ImportRow(rowView.Row);
}
}
FeatureDataSet dataSet = new FeatureDataSet();
provider.ExecuteIntersectionQuery(query, dataSet);
Assert.IsNotNull(dataSet);
Assert.IsNotNull(dataSet.Tables);
Assert.AreEqual(1, dataSet.Tables.Count);
FeatureDataTable actual = dataSet.Tables[0];
Assert.AreEqual(expected.Rows.Count, actual.Rows.Count);
foreach (DataRowView expectedRowView in expected.DefaultView)
{
DataRow[] actualRows = actual.Select("oid = " + expectedRowView["oid"]);
Assert.AreEqual(1, actualRows.Length);
Assert.AreEqual(expectedRowView["oid"], actualRows[0]["oid"]);
Assert.AreEqual(expectedRowView["x"], actualRows[0]["x"]);
Assert.AreEqual(expectedRowView["y"], actualRows[0]["y"]);
}
}
示例15: GetData
public JsonResult GetData(string layer, int z, int x, int y)
{
if (String.IsNullOrEmpty(layer))
throw new ArgumentNullException("layer");
Map map = ShapefileHelper.Spherical();
IQueryable<VectorLayer> coll = map.Layers
.AsQueryable()
.OfType<VectorLayer>()
.Where(l => l.Enabled && l.IsQueryEnabled)
.Where(l => String.Equals(l.LayerName, layer));
VectorLayer query = coll.SingleOrDefault();
if (query == null)
throw new ArgumentException("Layer not found: " + layer);
if (query.SRID != 4326)
throw new ArgumentException("Only EPSG:4326 supported");
using (Utf8Grid grid = new Utf8Grid(UtfGridResolution, x, y, z))
{
Envelope bbox = this.GetBoundingBoxInLatLngWithMargin(x, y, z);
FeatureDataSet ds = new FeatureDataSet();
query.ExecuteIntersectionQuery(bbox, ds);
IEnumerable<GeoJSON> data = GeoJSONHelper.GetData(ds);
int i = 1;
foreach (GeoJSON val in data)
{
IGeometry geom = val.Geometry;
IDictionary<string, object> dict = val.Values;
grid.FillPolygon(geom, i, dict);
i = i + 1;
}
Utf8GridResults results = grid.CreateUtfGridJson();
return this.Json(new { keys = results.Keys, data = results.Data, grid = results.Grid, }, JsonRequestBehavior.AllowGet);
}
}