本文整理汇总了C#中DotSpatial.Data.FeatureSet.AddFeature方法的典型用法代码示例。如果您正苦于以下问题:C# FeatureSet.AddFeature方法的具体用法?C# FeatureSet.AddFeature怎么用?C# FeatureSet.AddFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DotSpatial.Data.FeatureSet
的用法示例。
在下文中一共展示了FeatureSet.AddFeature方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Project
public static IGeometry Project(IGeometry geometry, ProjectionInfo pStart, ProjectionInfo pEnd)
{
var featureSet = new FeatureSet();
featureSet.AddFeature(geometry.ToDotSpatial());
featureSet.Projection = pStart;
featureSet.Reproject(pEnd);
return
GeometryConverter.ToGeoAPI(
((featureSet.Features[0].BasicGeometry as DotSpatial.Topology.IGeometry)));
}
示例2: GetAttributes_WithFieldNames
public void GetAttributes_WithFieldNames()
{
var fs = new FeatureSet(FeatureType.Point);
fs.DataTable.Columns.Add("Column1");
fs.DataTable.Columns.Add("Column2");
fs.AddFeature(new Point(0, 0));
var fl = new PointLayer(fs);
var target = new IndexSelection(fl);
var attributesTable = target.GetAttributes(0, 1, new[] {"Column1"});
Assert.AreEqual(1, attributesTable.Columns.Count);
Assert.AreEqual("Column1", attributesTable.Columns[0].ColumnName);
}
示例3: DelaunayLines
/// <summary>
/// The Voronoi Graph calculation creates a delaunay tesselation where
/// each point is effectively converted into triangles.
/// </summary>
/// <param name="points">The points to use for creating the tesselation.</param>
/// <returns>The generated line featureset.</returns>
public static IFeatureSet DelaunayLines(IFeatureSet points)
{
double[] vertices = points.Vertex;
VoronoiGraph gp = Fortune.ComputeVoronoiGraph(vertices);
FeatureSet result = new FeatureSet();
foreach (VoronoiEdge edge in gp.Edges)
{
Coordinate c1 = edge.RightData.ToCoordinate();
Coordinate c2 = edge.LeftData.ToCoordinate();
LineString ls = new LineString(new List<Coordinate> { c1, c2 });
Feature f = new Feature(ls);
result.AddFeature(f);
}
return result;
}
示例4: VoronoiLines
/// <summary>
/// The Voronoi Graph calculation creates the lines that form a voronoi diagram.
/// </summary>
/// <param name="points">The points to use for creating the tesselation.</param>
/// <returns>An IFeatureSet that is the resulting set of lines in the diagram.</returns>
public static IFeatureSet VoronoiLines(IFeatureSet points)
{
double[] vertices = points.Vertex;
VoronoiGraph gp = Fortune.ComputeVoronoiGraph(vertices);
HandleBoundaries(gp, points.Extent.ToEnvelope());
FeatureSet result = new FeatureSet();
foreach (VoronoiEdge edge in gp.Edges)
{
Coordinate c1 = edge.VVertexA.ToCoordinate();
Coordinate c2 = edge.VVertexB.ToCoordinate();
LineString ls = new LineString(new List<Coordinate> { c1, c2 });
Feature f = new Feature(ls);
result.AddFeature(f);
}
return result;
}
示例5: EraseFeatures
/// <summary>
/// Erase features from one feature set where they are intersected by another feature set.
/// </summary>
/// <param name="TargetFeatures">Features which will be erased in part or whole.</param>
/// <param name="SourceFeatures">Features which represent areas to erase.</param>
/// <param name="cancelProgressHandler">Optional parameter to report progress and cancel entire process if needed.</param>
/// <returns>A point feature set with the randomly created features.</returns>
public static FeatureSet EraseFeatures(IFeatureSet TargetFeatures, IFeatureSet SourceFeatures, ICancelProgressHandler cancelProgressHandler = null)
{
if (TargetFeatures == null || SourceFeatures == null)
{
return null;
}
//Erase features from one feature set where they are intersected by another feature set
//Note: we use the ShapeIndices here rather than for each feature in featureset.features as a memory management technique.
//The current version does not preserve any attribute info.
//Dan Ames 2/27/2013
FeatureSet ResultFeatures = new FeatureSet(); //the resulting featureset
IFeature TF, SF; //a single output feature
ResultFeatures.CopyTableSchema(TargetFeatures); //set up the data table in the new feature set
for (Int16 i = 0; i <= TargetFeatures.ShapeIndices.Count - 1; i++)
{
TF = TargetFeatures.GetFeature(i); //get the full undifferenced feature
for (Int16 j = 0; j <= SourceFeatures.ShapeIndices.Count - 1; j++)
{
SF = SourceFeatures.GetFeature(j);
if (SF.Envelope.Intersects(TF.Envelope))
{
TF = TF.Difference(SF); //clip off any pieces of SF that overlap FR
}
if (TF == null)
{ //sometimes difference leaves nothing left of a feature
break;
}
}
if (TF != null)
{
ResultFeatures.AddFeature(TF).CopyAttributes(TargetFeatures.GetFeature(i)); //add the fully clipped feature to the results
}
if (cancelProgressHandler != null)
{
if (cancelProgressHandler.Cancel) { return null; }
int progress = Convert.ToInt32(i * 100 / TargetFeatures.ShapeIndices.Count);
cancelProgressHandler.Progress(String.Empty, progress, String.Empty);
}
}
return ResultFeatures;
}
示例6: CreatefilterFeatureSet
private IFeatureSet CreatefilterFeatureSet()
{
IFeatureSet data1 = new FeatureSet(FeatureType.Point);
data1.Projection = _originalData.Projection;
data1.DataTable.Columns.Add(new System.Data.DataColumn(this.Field, typeof(double)));
data1.DataTable.Columns.Add(new System.Data.DataColumn("Repeat", typeof(string)));
List<int> listt = _originalData.SelectIndexByAttribute(Filterfields);
foreach (int index in listt)
{
IFeature fea1 = _originalData.GetFeature(index);
IFeature d=data1.AddFeature((IBasicGeometry)fea1);
d.DataRow[this.Field] = fea1.DataRow[this.Field];
}
return data1;
}
示例7: CreateFeatureSet
internal FeatureSet CreateFeatureSet()
{
FeatureSet featureSet = new FeatureSet(FeatureType.Line);
featureSet.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;
foreach (ReferentielMultiLineString mls in this.MultiLineStrings)
{
List<LineString> lineStrings = new List<LineString>();
foreach (ReferentielLineString ls in mls.LineStrings)
{
List<Coordinate> coordinates = new List<Coordinate>();
for (int i = 0; i < (ls.Segements.Count - 1); i++)
{
coordinates.Add(ls.Segements[i].CoordDeb);
}
coordinates.Add(ls.Segements.Last().CoordDeb);
coordinates.Add(ls.Segements.Last().CoordFin);
LineString fsLs = new LineString(coordinates);
lineStrings.Add(fsLs);
}
MultiLineString fsMls = new MultiLineString(lineStrings);
featureSet.AddFeature(fsMls);
}
return featureSet;
}
示例8: ClassifyPoint
public PointClassification ClassifyPoint(double latitude, double longitude)
{
FeatureSet pFeatureSet = new FeatureSet();
pFeatureSet.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;
DotSpatial.Topology.Point pPoint = new DotSpatial.Topology.Point(longitude, latitude);
FeatureSet pPointFeatureSet = new FeatureSet(DotSpatial.Topology.FeatureType.Point);
pPointFeatureSet.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;
pPointFeatureSet.AddFeature(pPoint);
Extent pAffectedExtent = null;
var result = fsWorldCountries.Select(pPointFeatureSet.Extent, out pAffectedExtent);
foreach (IFeature feature in result)
{
PointClassification classification = new PointClassification();
classification.CountryCode = feature.DataRow["ADM0_A3"].ToString();
if (classification.CountryCode.Length == 3) classification.CountryCode = ConvertISOCountryCode(classification.CountryCode);
classification.CountrySubdivision = feature.DataRow["NAME"].ToString();
classification.CountryName = feature.DataRow["ADMIN"].ToString();
return classification;
}
return null;
// System.Diagnostics.Debug.WriteLine(featureL);
}
示例9: SaveProfilesToShapeFile
public void SaveProfilesToShapeFile(FileInfo shapefile)
{
//clear existing profiles
ClearProfiles();
//read the rivers
ReadRivers();
List<Reach> reachesFixed = new List<Reach>();
List<Reach> reaches = (from n in rivers.Values
from p in n.Reaches.Values
select p).ToList();
for (int i = 0; i < reaches.Count; i++)
{
Reach r1 = reaches[i];
for (int j = 0; j < reaches.Count; j++)
{
if (j != i)
{
Reach r2 = reaches[j];
Point p1 = r1.CenterLine[r1.CenterLine.Count - 1];
Point p2 = r2.CenterLine[0];
if (Math.Abs((p1 - p2).Length()) < 200)
{
XSection x = r2.XSections.Values.First<XSection>();
r1.XSections.Add(x.StationName, x);
r1.CreateGISFeatures();
reachesFixed.Add(r1);
break;
}
}
}
}
//Create Shapefile using .dospatial library
using (IFeatureSet fsp = new FeatureSet(FeatureType.Polygon))
{
using (IFeatureSet trip = new FeatureSet(FeatureType.Polygon))
{
using (IFeatureSet fsxs = new FeatureSet(FeatureType.Line))
{
using (IFeatureSet fspo = new FeatureSet(FeatureType.Point))
{
//add attribute fields to attribute table
trip.DataTable.Columns.AddRange(new DataColumn[]
{
new DataColumn("RiverName" , typeof(string)),
new DataColumn("ReachName" , typeof(string)),
});
//add attribute fields to attribute table
fsp.DataTable.Columns.AddRange(new DataColumn[]
{
new DataColumn("RiverName" , typeof(string)),
new DataColumn("ReachName" , typeof(string)),
});
fsxs.DataTable.Columns.AddRange(new DataColumn[]
{
new DataColumn("RiverName" , typeof(string)),
new DataColumn("ReachName" , typeof(string)),
new DataColumn("StationName" , typeof(string)),
});
List<River> tempRivers = rivers.Values.ToList();
//select river
for (int j = 0; j < rivers.Count; j++)
{
River river = tempRivers[j];
foreach (Reach reach in river.Reaches.Values)
{
foreach (WaterSurfacePolygon wsurface in reach.WaterSurfaces)
{
List<Polygon> polygons = wsurface.GetPolygons();
foreach (Polygon polygon in polygons)
{
IFeature tri = trip.AddFeature(polygon);
tri.DataRow.BeginEdit();
tri.DataRow["RiverName"] = river.Name;
tri.DataRow["ReachName"] = reach.Name;
tri.DataRow.EndEdit();
}
}
IFeature fp = fsp.AddFeature(reach.BoundingPolygon);
fp.DataRow.BeginEdit();
fp.DataRow["RiverName"] = river.Name;
fp.DataRow["ReachName"] = reach.Name;
fp.DataRow.EndEdit();
//.........这里部分代码省略.........
示例10: GetStreamline
//.........这里部分代码省略.........
{
if (coordArray != null)
{
LineString[] lines = new LineString[coordArray.Count];
for (int j = 0; j < coordArray.Count; j++)//The second level branket
{
JArray linecoord = (JArray)coordArray[j];
IList<Coordinate> multicoords = new List<Coordinate>();
if (linecoord != null)
{
foreach (JArray latlongcoord in linecoord) //The first level branket
{
Coordinate coord = new Coordinate();
lon = latlongcoord[0].ToString();
lat = latlongcoord[1].ToString();
coord.X = Convert.ToDouble(lon);
coord.Y = Convert.ToDouble(lat);
multicoords.Add(coord);
}
lines[j] = new LineString(multicoords);
}
}
//Save lines[] into a multiline
IMultiLineString multilines = new MultiLineString(lines);
linef = new Feature(multilines);
}
}
//For the case GeoJSON returns a LineString
if (stype.Trim().ToLower() == "linestring")
{
IList<Coordinate> coords = new List<Coordinate>();
foreach (JArray latlongcoord in coordArray) //The second level branket
{
Coordinate coord = new Coordinate();
lon = latlongcoord[0].ToString();
lat = latlongcoord[1].ToString();
coord.X = Convert.ToDouble(lon, CultureInfo.InvariantCulture);
coord.Y = Convert.ToDouble(lat, CultureInfo.InvariantCulture);
coords.Add(coord);
}
linef = new Feature(FeatureType.Line, coords);
}
linefs.Projection = WGS84;
//Save features into a featureset
if (linefs.Features.Count == 0)
{
linefs.Projection = WGS84;
linefs = new FeatureSet(linef.FeatureType);
linefs.AddFeature(linef);
}
else
{
linefs.AddFeature(linef);
}
//Save streamlines' information
comid.Add(id);
reachcode.Add(code);
totdist.Add(dist);
}
//TODO: PK- use a StreamLine object with 4 properties instead - create this class in the Models folder
object[] streamlines = new object[4];
streamlines[0] = linefs as object;
streamlines[1] = comid as object;
streamlines[2] = reachcode as object;
streamlines[3] = totdist as object;
return streamlines;
}
catch (Exception ex)
{
var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
{
Content = new StringContent(ex.Message),
ReasonPhrase = "Error finding upstream flow lines with EPA web service."
};
throw new HttpResponseException(resp);
}
}
示例11: AppendFeatures
/// <summary>
/// Add the features from SourceFeatures to the TargetFeatures feature set.
/// </summary>
/// <param name="TargetFeatures">Feature set to which features will be added.</param>
/// <param name="SourceFeatures">Source of features to add to the target feature set. </param>
/// <returns>A point feature set with the randomly created features.</returns>
public static FeatureSet AppendFeatures(FeatureSet TargetFeatures, FeatureSet SourceFeatures)
{
//Add the features from SourceFeatures to the TargetFeatures feature set
//Note: we use the ShapeIndices here rather than for each feature in featureset.features as a memory management technique.
//Dan Ames 2/27/2013
IFeature SF;
for (Int16 j = 0; j <= SourceFeatures.ShapeIndices.Count - 1; j++)
{
SF = SourceFeatures.GetFeature(j);
TargetFeatures.AddFeature(SF).CopyAttributes(SourceFeatures.GetFeature(j)); //by default this will try to copy attributes over that have the same name.
}
return TargetFeatures;
}
示例12: RandomPoints
/// <summary>
/// Creates a specified number of random point features inside a single polygon feature.
/// </summary>
/// <param name="ConstrainingFeature">Random points will be generated inside this polygon feature.</param>
/// <param name="NumberOfPoints">The number of points to be randomly generated.</param>
/// <returns>A point feature set with the randomly created features.</returns>
public static FeatureSet RandomPoints(Feature ConstrainingFeature, int NumberOfPoints)
{
//This function generates random points within the boundaries of one polygon feature
FeatureSet fsOut = new FeatureSet();
fsOut.FeatureType = FeatureType.Point;
Coordinate c = new Coordinate();
Random r = new Random();
int i = 0;
while (i < NumberOfPoints)
{
c = new Coordinate();
//make a random point somewhere in the rectangular extents of the feature
double rndx = r.Next(0, 100000) / 100000.0;
double rndy = r.Next(0, 100000) / 100000.0;
c.X = rndx * (ConstrainingFeature.Envelope.Right() - ConstrainingFeature.Envelope.Left()) + ConstrainingFeature.Envelope.Left();
c.Y = rndy * (ConstrainingFeature.Envelope.Top() - ConstrainingFeature.Envelope.Bottom()) + ConstrainingFeature.Envelope.Bottom();
//check if the point falls within the polygon featureset
if (ConstrainingFeature.Intersects(c))
{
fsOut.AddFeature(new Feature(c));
i++;
}
}
return fsOut;
}
示例13: UnionAll
private static IFeatureSet UnionAll(IFeatureSet fs)
{
FeatureSet fsunion = new FeatureSet();
fsunion.CopyTableSchema(fs);
fsunion.Projection = fs.Projection;
IFeature f = fs.Features[0];
for (int i = 1; i < fs.Features.Count; i++)
{
f = f.Union(fs.Features[i], fsunion, FieldJoinType.LocalOnly);
}
fsunion.AddFeature(f);
return fsunion;
}
示例14: ConvertToPoints
private IFeatureSet ConvertToPoints(IFeatureSet originalData)
{
string field = Field;
IFeatureSet fea = new FeatureSet(FeatureType.Point);
fea.Projection = originalData.Projection;
DataColumn col = originalData.GetColumn(field);
DataColumn coln = new DataColumn(col.ColumnName, col.DataType);
fea.DataTable.Columns.Add(coln);
foreach (Feature feature in originalData.Features)
{
foreach (Coordinate c in feature.BasicGeometry.Coordinates)
{
IFeature nfeature = fea.AddFeature(new DotSpatial.Topology.Point(c.X, c.Y));
nfeature.DataRow[field] = feature.DataRow[field];
}
}
return fea;
}
示例15: CalculateProductForm_Shown
private void CalculateProductForm_Shown(object sender, EventArgs e)
{
if (_field != null)
{
label1.Text = "Reading Polygon..";
var polygonFile = Path.Combine(_field.Folder, "input_polygon.shp");
var polygonFeatures = FeatureSet.Open(polygonFile).Features;
label1.Text = "Reading Grid..";
var gridFile = Path.Combine(_field.Folder, "grid_points.shp");
var featuresDataset = FeatureSet.Open(gridFile);
progressBar1.Maximum = polygonFeatures.Count;
progressBar1.Value = 0;
var newPolygonLayer = new FeatureSet(FeatureType.Polygon);
var tbl = new DataTable();
tbl.Columns.Add("Z");
tbl.Columns.Add("AreaM2");
tbl.Columns.Add("Hectare");
int pCount = 1;
foreach (Feature poly in polygonFeatures)
{
label1.Text = "Caculating Product Value for plot:" + pCount;
var extent = poly.Envelope.ToExtent();
var fe = featuresDataset.CopySubset(featuresDataset.SelectIndices(extent));
double zTotalCount = 0;
for (int i = 0; i < fe.Features.Count; i++)
{
if (poly.Contains(fe.Features[i]))
{
var z = double.Parse(Convert.ToString(fe.DataTable.Rows[i]["Z"]));
zTotalCount += z;
}
}
tbl.Rows.Add(Math.Round(zTotalCount / 25, 2), Math.Round(poly.Area(), 2), Math.Round(poly.Area() / 10000, 0));
newPolygonLayer.AddFeature(poly);
progressBar1.Value = progressBar1.Value + 1;
pCount++;
}
newPolygonLayer.DataTable = tbl;
newPolygonLayer.Projection = _map.Projection;
newPolygonLayer.Reproject(_map.Projection);
var newPolyFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TempFiles", "Temp-Product" + DateTime.Now.Ticks + ".shp");
newPolygonLayer.SaveAs(newPolyFile, true);
var layer = _map.Layers.Add(newPolyFile);
layer.ContextMenuItems.Add(
new DotSpatial.Symbology.SymbologyMenuItem("Save Product File", new EventHandler((s, ev) => SaveProductFileClick(s, ev, (IMapPolygonLayer)layer))));
label1.Text = "Completed";
}
}