public Boolean Evaluate(Feature feature) { if (feature.geometry == null) { return(false); } switch (feature.geometry.geometryType) { case OSGeo.OGR.wkbGeometryType.wkbPoint: PointD point_data = (PointD)feature.geometry; PointD point_map = this.rsTransfrom.sourceToTarget(point_data); return(SpatialTopology.IsPointInRectangle(point_map, this.rect)); case OSGeo.OGR.wkbGeometryType.wkbPolygon: SimplePolygon polygon_data = (SimplePolygon)feature.geometry; return(checksimplepolygon(polygon_data)); case OSGeo.OGR.wkbGeometryType.wkbLineString: SimplePolyline line_data = (SimplePolyline)feature.geometry; return(checkpolyline(line_data)); case OSGeo.OGR.wkbGeometryType.wkbMultiPolygon: Polygon mutipolygon_data = (Polygon)feature.geometry; return(checkmutipolygon(mutipolygon_data)); case OSGeo.OGR.wkbGeometryType.wkbMultiLineString: break; } //to do return(false); }
public bool checkmutipolyline(Polyline polyline) { for (int i = 0; i < polyline.childPolylines.Count; i++) { SimplePolyline simple = polyline.childPolylines[i]; if (checkpolyline(simple)) { return(true); } } return(false); }
public bool checkpolyline(SimplePolyline polyline_data) { List <PointD> polyline_points_map = new List <PointD>(); int pointcount = polyline_data.points.Count; for (int i = 0; i < pointcount; i++) { polyline_points_map.Add(rsTransfrom.sourceToTarget(polyline_data.points[i])); } SimplePolyline polyline_map = new SimplePolyline(polyline_points_map); return(SpatialTopology.IsSimplePolyLineInRectangle(polyline_map, rect)); }
public bool checksimplepolygon(SimplePolygon polygon_data) { List <PointD> ring0_points_data = polygon_data.rings[0].points; List <PointD> ring0_points_map = new List <PointD>(); for (int i = 0; i < ring0_points_data.Count; i++) { ring0_points_map.Add(this.rsTransfrom.sourceToTarget(ring0_points_data[i])); } SimplePolyline ring0 = new SimplePolyline(ring0_points_map); List <SimplePolyline> temp = new List <SimplePolyline>(); temp.Add(ring0); SimplePolygon polygon_map = new SimplePolygon(temp); return(SpatialTopology.IsSimplePolygonIntersectRect(polygon_map, this.rect)); }
public static string SimplePolyline2String(SimplePolyline geom) { string s = "("; List <PointD> points = geom.points; for (int i = 0; i < points.Count; i++) { if (i > 0) { s += ","; } s += PointD2String(points[i]); } return(s + ")"); }
public bool CheckIsPointSelectedofSelectedFeatureCollection(PointD mouselocation, double interval) { if (selectedFeatureCollection == null || selectedFeatureCollection.featureList.Count == 0) { return(false); } foreach (Feature feature in selectedFeatureCollection.featureList) { switch (feature.geometry.geometryType) { case OSGeo.OGR.wkbGeometryType.wkbPoint: if (SpatialTopology.GetDistanceBetweenPoints((PointD)feature.geometry, mouselocation) < interval) { this.selectedPoint = (PointD)feature.geometry; return(true); } break; case OSGeo.OGR.wkbGeometryType.wkbLineString: SimplePolyline simpleline = (SimplePolyline)feature.geometry; foreach (PointD linepoint in simpleline.points) { if (SpatialTopology.GetDistanceBetweenPoints(linepoint, mouselocation) < interval) { this.selectedPoint = linepoint; return(true); } } break; case OSGeo.OGR.wkbGeometryType.wkbPolygon: SimplePolygon simplepolygon = (SimplePolygon)feature.geometry; foreach (SimplePolyline ring in simplepolygon.rings) { foreach (PointD linepoint in ring.points) { if (SpatialTopology.GetDistanceBetweenPoints(linepoint, mouselocation) < interval) { this.selectedPoint = linepoint; return(true); } } } break; } } this.selectedPoint = null; return(false); }
public void FinishEdit() { lists.Add(editingpoints); switch (geometrytype) { case OSGeo.OGR.wkbGeometryType.wkbPoint: foreach (List <PointD> onelist in lists) { for (int i = 0; i < onelist.Count; i++) { Feature pointfeature = new Feature(EditingFeaturesource.GetNextFeatureID(), EditingFeaturesource.schema, onelist[i]); LogItem_CreateFeature logitem_create_point = new LogItem_CreateFeature(this.layername, pointfeature.featureID); Utils.gislog.AddLog(logitem_create_point); EditingFeaturesource.features.InsertFeature(pointfeature); } } break; case OSGeo.OGR.wkbGeometryType.wkbLineString: foreach (List <PointD> onelist in lists) { SimplePolyline simplepolyline = new SimplePolyline(onelist); Feature linefeature = new Feature(EditingFeaturesource.GetNextFeatureID(), EditingFeaturesource.schema, simplepolyline); LogItem_CreateFeature logitem_create_line = new LogItem_CreateFeature(this.layername, linefeature.featureID); Utils.gislog.AddLog(logitem_create_line); EditingFeaturesource.features.InsertFeature(linefeature); } break; case OSGeo.OGR.wkbGeometryType.wkbPolygon: List <SimplePolyline> rings = new List <SimplePolyline>(); foreach (List <PointD> onelist in lists) { onelist.Add(onelist.First()); SimplePolyline onering = new SimplePolyline(onelist); rings.Add(onering); } SimplePolygon simplepolygon = new SimplePolygon(rings); Feature polygonfeature = new Feature(EditingFeaturesource.GetNextFeatureID(), EditingFeaturesource.schema, simplepolygon); LogItem_CreateFeature logitem_create_polygon = new LogItem_CreateFeature(this.layername, polygonfeature.featureID); Utils.gislog.AddLog(logitem_create_polygon); EditingFeaturesource.features.InsertFeature(polygonfeature); break; } this.editstatus = EditStatus.finished; }
public static bool IsSimplePolyLineInRectangle(SimplePolyline simplepolyline, Rectangle rect) { //判断外包矩形,如果外包矩形不想交,则立即返回 Rectangle polyrec = simplepolyline.getEnvelop(); if (!IsRectangleIntersect(polyrec, rect)) { return(false); } //判断每条线是否与矩形相交 List <PointD> points = simplepolyline.points; int pointcount = points.Count; for (int i = 0; i < pointcount - 1; i++) { if (IsSegmentIntersectsegment(points[i], points[i + 1], new PointD(rect.minX, rect.minY), new PointD(rect.minX, rect.maxY))) { return(true); } if (IsSegmentIntersectsegment(points[i], points[i + 1], new PointD(rect.minX, rect.minY), new PointD(rect.maxX, rect.minY))) { return(true); } if (IsSegmentIntersectsegment(points[i], points[i + 1], new PointD(rect.maxX, rect.minY), new PointD(rect.maxX, rect.maxY))) { return(true); } if (IsSegmentIntersectsegment(points[i], points[i + 1], new PointD(rect.minX, rect.maxY), new PointD(rect.maxX, rect.maxY))) { return(true); } } //判断点是否在矩形内,若一个点在矩形内,则该多边形在矩形内 if (pointcount > 0) { PointD polygonpoint = points.First(); if (IsPointInRectangle(polygonpoint, rect)) { return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="offsetx"></param> /// <param name="offsety"></param> public void SelectedFeaturesPan(double offsetx, double offsety, FeatureCollection collection) { if (collection == null || collection.featureList.Count == 0) { return; } foreach (Feature feature in collection.featureList) { Geometry.Geometry geo = feature.geometry; switch (geo.geometryType) { case OSGeo.OGR.wkbGeometryType.wkbPoint: PointD point = (PointD)geo; point.X -= offsetx; point.Y -= offsety; break; case OSGeo.OGR.wkbGeometryType.wkbLineString: SimplePolyline line = (SimplePolyline)geo; foreach (PointD ringpoint in line.points) { ringpoint.X -= offsetx; ringpoint.Y -= offsety; } break; case OSGeo.OGR.wkbGeometryType.wkbPolygon: SimplePolygon simplegon = (SimplePolygon)geo; foreach (SimplePolyline ring in simplegon.rings) { foreach (PointD ringpoint in ring.points) { ringpoint.X -= offsetx; ringpoint.Y -= offsety; } } break; } } }
/// <summary> /// 完成编辑并将当前编辑的图形作为要素加入列表 /// </summary> public void Complete() { Feature tmpFeat = new Feature(this.maxFid + 1, this.editedLayer.featuresource.schema, null); switch (this.editedLayer.featuresource.schema.geometryType) { case OSGeo.OGR.wkbGeometryType.wkbPoint: if (this._inputTmp.Count > 0) { tmpFeat.SetGeometry(this._inputTmp.ElementAt(0)); } this._features.InsertFeature(tmpFeat); break; case OSGeo.OGR.wkbGeometryType.wkbLineString: if (this._inputTmp.Count < 2) { break; } SimplePolyline tmpSL = new SimplePolyline(this._inputTmp); tmpFeat.SetGeometry(tmpSL); this._features.InsertFeature(tmpFeat); break; case OSGeo.OGR.wkbGeometryType.wkbPolygon: if (this._inputTmp.Count < 3) { break; } List <SimplePolyline> tmpSLL = new List <SimplePolyline>(); tmpSLL.Add(new SimplePolyline(this._inputTmp)); SimplePolygon tmpSG = new SimplePolygon(tmpSLL); tmpFeat.SetGeometry(tmpSG); this._features.InsertFeature(tmpFeat); break; } //prepare for another input this._inputTmp = new List <PointD>(); }
/// <summary> /// 完成编辑并将当前图形作为一个子图形加入一个要素,只能加入此次编辑的要素中 /// 这个过程中,被加入要素如果是SimplePolygon/line类型则会被转为MultiPolygon/line类型 /// 如果被加入的是点要素,则只完成并新建一个点要素 /// </summary> /// <param name="FID"></param> public void CompleteAndAddTo(int FID) { Feature tmpFeat; switch (this.editedLayer.featuresource.schema.geometryType) { case OSGeo.OGR.wkbGeometryType.wkbPoint: this.Complete(); break; case OSGeo.OGR.wkbGeometryType.wkbLineString: if (this._inputTmp.Count < 2) { this._inputTmp = new List <PointD>(); break; } SimplePolyline tmpSL = new SimplePolyline(this._inputTmp); tmpFeat = this._features.GetFeatureByID(FID); //if this id do not correspond to a feature, we'll give up the inputted data if (tmpFeat == null) { this._inputTmp = new List <PointD>(); return; } Polyline tmpML; List <SimplePolyline> tmpSLs = new List <SimplePolyline>(); switch (tmpFeat.geometry.geometryType) { case OSGeo.OGR.wkbGeometryType.wkbLineString: tmpSLs.Add((SimplePolyline)tmpFeat.geometry); break; case OSGeo.OGR.wkbGeometryType.wkbMultiLineString: foreach (SimplePolyline pl in ((Polyline)tmpFeat.geometry).childPolylines) { tmpSLs.Add(pl); } break; } tmpSLs.Add(tmpSL); tmpML = new Polyline(tmpSLs); tmpFeat.SetGeometry(tmpML); break; case OSGeo.OGR.wkbGeometryType.wkbPolygon: if (this._inputTmp.Count < 3) { this._inputTmp = new List <PointD>(); break; } List <SimplePolyline> tmpSLL = new List <SimplePolyline>(); tmpSLL.Add(new SimplePolyline(this._inputTmp)); SimplePolygon tmpSG = new SimplePolygon(tmpSLL); tmpFeat = this._features.GetFeatureByID(FID); //if this id do not correspond to a feature, we'll give up the inputted data if (tmpFeat == null) { this._inputTmp = new List <PointD>(); return; } Polygon tmpMG; List <SimplePolygon> tmpSGs = new List <SimplePolygon>(); switch (tmpFeat.geometry.geometryType) { case OSGeo.OGR.wkbGeometryType.wkbPolygon: tmpSGs.Add((SimplePolygon)tmpFeat.geometry); break; case OSGeo.OGR.wkbGeometryType.wkbMultiPolygon: foreach (SimplePolygon pg in ((Polygon)tmpFeat.geometry).childPolygons) { tmpSGs.Add(pg); } break; } tmpSGs.Add(tmpSG); tmpMG = new Polygon(tmpSGs); tmpFeat.SetGeometry(tmpMG); //prepare for another input this._inputTmp = new List <PointD>(); break; } }
public static string SimplePolyline2WKT(SimplePolyline geom) { string s = "LINESTRING" + SimplePolyline2String(geom); return(s); }
public static JGeometry.LineString Polyline2JG(SimplePolyline simplePolyline) { return(Points2LineString(simplePolyline.points)); }
public Rectangle getEnvelop() { if (this.count == 0) { return(new Rectangle(0, 0, 0, 0)); } Rectangle rect = new Rectangle(Utils.double_max, Utils.double_max, Utils.double_min, Utils.double_min); foreach (Feature feature in featureList) { OSGeo.OGR.wkbGeometryType featType = feature.geometry.geometryType; switch (featType) { case OSGeo.OGR.wkbGeometryType.wkbPoint: PointD point = (PointD)feature.geometry; if (point.X < rect.minX) { rect.minX = point.X; } if (point.X > rect.maxX) { rect.maxX = point.X; } if (point.Y < rect.minY) { rect.minY = point.Y; } if (point.Y > rect.maxY) { rect.maxY = point.Y; } break; case OSGeo.OGR.wkbGeometryType.wkbLineString: SimplePolyline line = (SimplePolyline)feature.geometry; if (line.minX < rect.minX) { rect.minX = line.minX; } if (line.maxX > rect.maxX) { rect.maxX = line.maxX; } if (line.minY < rect.minY) { rect.minY = line.minY; } if (line.maxY > rect.maxY) { rect.maxY = line.maxY; } break; case OSGeo.OGR.wkbGeometryType.wkbMultiLineString: Polyline mline = (Polyline)feature.geometry; if (mline.minX < rect.minX) { rect.minX = mline.minX; } if (mline.maxX > rect.maxX) { rect.maxX = mline.maxX; } if (mline.minY < rect.minY) { rect.minY = mline.minY; } if (mline.maxY > rect.maxY) { rect.maxY = mline.maxY; } break; case OSGeo.OGR.wkbGeometryType.wkbPolygon: SimplePolygon polygon = (SimplePolygon)feature.geometry; if (polygon.minX < rect.minX) { rect.minX = polygon.minX; } if (polygon.maxX > rect.maxX) { rect.maxX = polygon.maxX; } if (polygon.minY < rect.minY) { rect.minY = polygon.minY; } if (polygon.maxY > rect.maxY) { rect.maxY = polygon.maxY; } break; case OSGeo.OGR.wkbGeometryType.wkbMultiPolygon: Polygon mpolygon = (Polygon)feature.geometry; if (mpolygon.minX < rect.minX) { rect.minX = mpolygon.minX; } if (mpolygon.maxX > rect.maxX) { rect.maxX = mpolygon.maxX; } if (mpolygon.minY < rect.minY) { rect.minY = mpolygon.minY; } if (mpolygon.maxY > rect.maxY) { rect.maxY = mpolygon.maxY; } break; } } return(rect); }