protected override Road GetRoadByIdCore(string roadId) { Feature feature = featureSource.GetFeatureById(roadId, ReturningColumnsType.NoColumns); LineBaseShape sourceShape = (LineBaseShape)feature.GetShape(); Collection <LineShape> lines = ConvertLineBaseShapeToLines(sourceShape); List <string> adjacentIDs = new List <string>(); foreach (LineShape line in lines) { Collection <Feature> features = featureSource.GetFeaturesInsideBoundingBox(line.GetBoundingBox(), ReturningColumnsType.NoColumns); foreach (Feature tempFeature in features) { BaseShape tempShape = tempFeature.GetShape(); if (feature.Id != tempFeature.Id && line.Intersects(tempShape)) { adjacentIDs.Add(tempFeature.Id); } } } //adjacentIDs.Sort(); PointShape center = sourceShape.GetCenterPoint(); float centerX = (float)center.X; float centerY = (float)center.Y; float length = (float)sourceShape.GetLength(GeographyUnit.Meter, DistanceUnit.Meter); Road road = new Road(roadId, RoadType.LocalRoad, length, adjacentIDs, centerX, centerY, roadId); return(road); }
private Collection <Feature> GetAdjacentFeaturesOfVertex(FeatureSource featureSource, Vertex vertex) { RectangleShape startSmallBounds = GeometryHelper.CreateSmallRectangle(vertex, tolerance); // Get all the lines in current processing shape bounds. Collection <Feature> adjacentFeatures = featureSource.GetFeaturesInsideBoundingBox(startSmallBounds, ReturningColumnsType.AllColumns); return(adjacentFeatures); }
private static void GetAdjacentFeataureIds(FeatureSource featureSource, LineShape sourceShape, Collection <string> startIds, Collection <string> endIds) { Vertex startVertex = sourceShape.Vertices[0]; Vertex endVertex = sourceShape.Vertices[sourceShape.Vertices.Count - 1]; Collection <Feature> tempfeatures = featureSource.GetFeaturesInsideBoundingBox(sourceShape.GetBoundingBox(), ReturningColumnsType.NoColumns); foreach (Feature tempFeature in tempfeatures) { LineShape tempShape = ((MultilineShape)tempFeature.GetShape()).Lines[0]; if (sourceShape.Id == tempFeature.Id) { continue; } if (tempShape.Vertices.Contains(startVertex)) { startIds.Add(tempFeature.Id); } else if (tempShape.Vertices.Contains(endVertex)) { endIds.Add(tempFeature.Id); } } }
private void WriteFeaturesIntoQueue(Collection <Feature> features, FeatureSource featureSource) { foreach (Feature feature in features) { Collection <LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature); // Get the lineshape of the processing feature. foreach (LineShape processingLineShape in processingLineShapes) { // Define a variable to save the points where the adjacent lines intersect with current processing line. Collection <PointShape> crossingPoints = new Collection <PointShape>(); // Get all the lines in current processing shape bounds. Collection <Feature> adjacentFeatures = featureSource.GetFeaturesInsideBoundingBox(processingLineShape.GetBoundingBox(), ReturningColumnsType.NoColumns); // Loop and see if the queried shape is intersected with processing shape. foreach (Feature adjacentFeature in adjacentFeatures) { LineBaseShape adjacentLineShape = adjacentFeature.GetShape() as LineBaseShape; MultipointShape tempCrossingPoints = processingLineShape.GetCrossing(adjacentLineShape); // The queried shape is intersected with processing shape. foreach (PointShape point in tempCrossingPoints.Points) { bool hasAdded = false; foreach (var item in crossingPoints) { if (point.X == item.X && point.Y == item.Y) { hasAdded = true; break; } } if (!hasAdded) { crossingPoints.Add(point); } } } // Order the crossing points following the sequence of line vertex. Collection <FlagedVertex> vertecesOfNewLine = GeometryHelper.AddCrossingPointToLine(processingLineShape, crossingPoints); Collection <Vertex> verteces = new Collection <Vertex>(); Collection <Feature> lineFeatures = new Collection <Feature>(); foreach (var vertex in vertecesOfNewLine) { verteces.Add(vertex.Vertex); if (vertex.Flag) { if (verteces.Count >= 2) { LineShape segment = new LineShape(verteces); lineFeatures.Add(new Feature(segment, feature.ColumnValues)); verteces.RemoveAt(0); } } } if (lineFeatures.Count > 0) { queue.Enqueue(lineFeatures); } } #if DEBUG Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, features.Count)); #endif } }
private void WriteFeaturesIntoQueue(Collection<Feature> features, FeatureSource featureSource) { foreach (Feature feature in features) { Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature); // Get the lineshape of the processing feature. foreach (LineShape processingLineShape in processingLineShapes) { // Define a variable to save the points where the adjacent lines intersect with current processing line. Collection<PointShape> crossingPoints = new Collection<PointShape>(); // Get all the lines in current processing shape bounds. Collection<Feature> adjacentFeatures = featureSource.GetFeaturesInsideBoundingBox(processingLineShape.GetBoundingBox(), ReturningColumnsType.NoColumns); // Loop and see if the queried shape is intersected with processing shape. foreach (Feature adjacentFeature in adjacentFeatures) { LineBaseShape adjacentLineShape = adjacentFeature.GetShape() as LineBaseShape; MultipointShape tempCrossingPoints = processingLineShape.GetCrossing(adjacentLineShape); // The queried shape is intersected with processing shape. foreach (PointShape point in tempCrossingPoints.Points) { bool hasAdded = false; foreach (var item in crossingPoints) { if (point.X == item.X && point.Y == item.Y) { hasAdded = true; break; } } if (!hasAdded) { crossingPoints.Add(point); } } } // Order the crossing points following the sequence of line vertex. Collection<FlagedVertex> vertecesOfNewLine = GeometryHelper.AddCrossingPointToLine(processingLineShape, crossingPoints); Collection<Vertex> verteces = new Collection<Vertex>(); Collection<Feature> lineFeatures = new Collection<Feature>(); foreach (var vertex in vertecesOfNewLine) { verteces.Add(vertex.Vertex); if (vertex.Flag) { if (verteces.Count >= 2) { LineShape segment = new LineShape(verteces); lineFeatures.Add(new Feature(segment, feature.ColumnValues)); verteces.RemoveAt(0); } } } if (lineFeatures.Count > 0) { queue.Enqueue(lineFeatures); } } #if DEBUG Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, features.Count)); #endif } }
private Collection<Feature> GetAdjacentFeaturesOfVertex(FeatureSource featureSource, Vertex vertex) { RectangleShape startSmallBounds = GeometryHelper.CreateSmallRectangle(vertex, tolerance); // Get all the lines in current processing shape bounds. Collection<Feature> adjacentFeatures = featureSource.GetFeaturesInsideBoundingBox(startSmallBounds, ReturningColumnsType.AllColumns); return adjacentFeatures; }
private IEnumerable <Feature> StandardClip(FeatureSource featureSource, IEnumerable <Feature> features) { lock (featureSource) { Collection <Feature> results = new Collection <Feature>(); //There is a bug about projection boundingbox, here is a workaround for it. bool isOpen = false; Projection tmpProjection = null; if (featureSource.Projection != null && featureSource.Projection is GISEditorManagedProj4Projection && ((GISEditorManagedProj4Projection)featureSource.Projection).IsProjectionParametersEqual) { tmpProjection = featureSource.Projection; if (featureSource.IsOpen) { featureSource.Close(); featureSource.Projection.Close(); isOpen = true; } featureSource.Projection = null; } if (!featureSource.IsOpen) { featureSource.Open(); } Collection <Feature> sourceFeatures = featureSource.GetFeaturesInsideBoundingBox(ExtentHelper.GetBoundingBoxOfItems(features), ReturningColumnsType.AllColumns); if (tmpProjection != null) { featureSource.Projection = tmpProjection; if (isOpen) { featureSource.Open(); } } ShapeFileType shapeFileType = ((ShapeFileFeatureSource)featureSource).GetShapeFileType(); if (featureSource.IsOpen) { featureSource.Close(); } int index = 1; int count = sourceFeatures.Count; if (shapeFileType == ShapeFileType.Point || shapeFileType == ShapeFileType.Multipoint) { return(StandardClipPoints(sourceFeatures, features, shapeFileType)); } else if (shapeFileType == ShapeFileType.Polyline) { MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(features)); foreach (var feature in sourceFeatures) { ReportProgress(index * 100 / count); index++; try { if (areaBaseShape.Contains(feature)) { results.Add(feature); } else { var clippedShape = ((LineBaseShape)feature.GetShape()).GetIntersection(areaBaseShape); if (clippedShape != null && clippedShape.Lines.Count > 0) { results.Add(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues)); } } } catch (Exception ex) { HandleExceptionFromInvalidFeature(feature.Id, ex.Message); } } } else if (shapeFileType == ShapeFileType.Polygon) { MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(features)); foreach (var feature in sourceFeatures) { ReportProgress(index * 100 / count); try { index++; if (areaBaseShape.Contains(feature)) { results.Add(feature); } else { var clippedShape = areaBaseShape.GetIntersection(feature); if (clippedShape != null && clippedShape.Polygons.Count > 0) { results.Add(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues)); } } } catch (Exception ex) { HandleExceptionFromInvalidFeature(feature.Id, ex.Message); } } } else { throw new NotSupportedException("The ShapeFileType is not supported."); } return(results); } }
private IEnumerable <Feature> InverseClip(FeatureSource featureSource, IEnumerable <Feature> clippingFeatures) { lock (featureSource) { if (!featureSource.IsOpen) { featureSource.Open(); } Collection <Feature> results = featureSource.GetFeaturesOutsideBoundingBox(ExtentHelper.GetBoundingBoxOfItems(clippingFeatures), ReturningColumnsType.AllColumns); Collection <Feature> sourceFeatures = new Collection <Feature>(); ShapeFileType shapeFileType = ((ShapeFileFeatureSource)featureSource).GetShapeFileType(); int index = 1; if (shapeFileType == ShapeFileType.Point || shapeFileType == ShapeFileType.Multipoint) { featureSource.Open(); Collection <Feature> allFeatures = featureSource.GetAllFeatures(ReturningColumnsType.AllColumns); featureSource.Close(); foreach (Feature f in results) { allFeatures.Remove(f); } foreach (var f in InverseClipPoints(allFeatures, clippingFeatures, shapeFileType)) { results.Add(f); } } else if (shapeFileType == ShapeFileType.Polyline) { bool isOpen = false; Projection tmpProjection = null; MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(clippingFeatures)); if (featureSource.Projection != null && featureSource.Projection is GISEditorManagedProj4Projection && ((GISEditorManagedProj4Projection)featureSource.Projection).IsProjectionParametersEqual) { tmpProjection = featureSource.Projection; if (featureSource.IsOpen) { featureSource.Close(); featureSource.Projection.Close(); isOpen = true; } featureSource.Projection = null; } featureSource.Open(); featureSource.GetFeaturesInsideBoundingBox(areaBaseShape.GetBoundingBox(), ReturningColumnsType.AllColumns).ForEach(f => { if (!areaBaseShape.Contains(f)) { sourceFeatures.Add(f); } }); int count = sourceFeatures.Count; if (tmpProjection != null) { featureSource.Projection = tmpProjection; if (isOpen) { featureSource.Open(); } } if (featureSource.IsOpen) { featureSource.Close(); } foreach (var feature in sourceFeatures) { ReportProgress(index * 100 / count); index++; try { if (areaBaseShape.IsDisjointed(feature)) { results.Add(feature); } else { MultilineShape multiLine = (MultilineShape)feature.GetShape(); MultilineShape resultShape = new MultilineShape(); foreach (LineShape lineShape in multiLine.Lines) { if (areaBaseShape.IsDisjointed(lineShape)) { resultShape.Lines.Add(lineShape); } else { Collection <PointShape> points = new Collection <PointShape>(); points.Add(new PointShape(lineShape.Vertices[0])); lineShape.GetIntersection(areaBaseShape).Lines.ForEach(l => { PointShape p1 = new PointShape(l.Vertices[0]); if (points.Count(p => p.X == p1.X && p.Y == p1.Y && p.Z == p1.Z) <= 0) { points.Add(p1); } PointShape p2 = new PointShape(l.Vertices[l.Vertices.Count - 1]); if (points.Count(p => p.X == p2.X && p.Y == p2.Y && p.Z == p2.Z) <= 0) { points.Add(p2); } }); PointShape endPoint = new PointShape(lineShape.Vertices[lineShape.Vertices.Count - 1]); if (points.Count(p => p.X == endPoint.X && p.Y == endPoint.Y && p.Z == endPoint.Z) <= 0) { points.Add(endPoint); } for (int i = 0; i < points.Count; i++) { if (i != points.Count - 1) { LineBaseShape lineBaseShape = lineShape.GetLineOnALine(points[i], points[i + 1]); if (!areaBaseShape.Intersects(lineBaseShape.GetCenterPoint())) { resultShape.Lines.Add((LineShape)lineBaseShape); } } } } } if (resultShape != null && resultShape.Lines.Count > 0) { results.Add(new Feature(resultShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues)); } } } catch (Exception ex) { HandleExceptionFromInvalidFeature(feature.Id, ex.Message); } } } else if (shapeFileType == ShapeFileType.Polygon) { MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(clippingFeatures)); bool isOpen = false; Projection tmpProjection = null; if (featureSource.Projection != null && featureSource.Projection is GISEditorManagedProj4Projection && ((GISEditorManagedProj4Projection)featureSource.Projection).IsProjectionParametersEqual) { tmpProjection = featureSource.Projection; if (featureSource.IsOpen) { featureSource.Close(); featureSource.Projection.Close(); isOpen = true; } featureSource.Projection = null; } if (!featureSource.IsOpen) { featureSource.Open(); } featureSource.GetFeaturesInsideBoundingBox(areaBaseShape.GetBoundingBox(), ReturningColumnsType.AllColumns).ForEach(f => { if (!areaBaseShape.IsDisjointed(f)) { sourceFeatures.Add(f); } }); if (featureSource.IsOpen) { featureSource.Close(); } if (tmpProjection != null) { featureSource.Projection = tmpProjection; if (isOpen) { featureSource.Open(); } } int count = sourceFeatures.Count; foreach (var feature in sourceFeatures) { ReportProgress(index * 100 / count); index++; try { if (areaBaseShape.IsDisjointed(feature)) { results.Add(feature); } else { var clippedShape = ((AreaBaseShape)feature.GetShape()).GetDifference(areaBaseShape); if (clippedShape != null && clippedShape.Polygons.Count > 0) { results.Add(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues)); } } } catch (Exception ex) { HandleExceptionFromInvalidFeature(feature.Id, ex.Message); } } } else { throw new NotSupportedException("The ShapeFileType is not supported."); } return(results); } }