コード例 #1
0
        public static IList<RawProvince> Provinces(string text)
        {
            IList<RawProvince> provinces = new List<RawProvince>();

            ProvinceBuilder provBuilder = new ProvinceBuilder();
            PolygonBuilder  polyBuilder = new PolygonBuilder();

            foreach (string line in Lines(text))
            {
                Vector2[] vectors;

                switch (line[0])
                {
                case '§':  // New province
                    if (provBuilder.Tag != "")
                    {
                        provBuilder.Polys.Add(polyBuilder.Build());
                        provinces.Add(provBuilder.Build());
                    }

                    string[] tokens = line.Split(' ');
                    provBuilder.Tag = tokens[0].Substring(1);

                    if (!TryParseHexColor(tokens[1], out provBuilder.Color))
                    {
                        Console.Error.WriteLine("Failed to parse color: " + tokens[1]);
                    }
                    break;
                case '\\': // New hole to existing polygon
                    vectors = ParseVectors(line.Substring(1));
                    polyBuilder.Holes.Add(new Poly(vectors));
                    break;
                default:   // New polygon
                    vectors = ParseVectors(line);

                    if (polyBuilder.Outline != null)
                    {
                        provBuilder.Polys.Add(polyBuilder.Build());
                    }

                    polyBuilder.Outline = new Poly(vectors);
                    break;
                }
            }

            provBuilder.Polys.Add(polyBuilder.Build());
            provinces.Add(provBuilder.Build());
            return provinces;
        }
コード例 #2
0
ファイル: OverlayOp.cs プロジェクト: spacefan/iGeospatial
		private void ComputeOverlay(OverlayType opCode)
		{
			// copy points from input Geometries.
			// This ensures that any Point geometries
			// in the input are considered for inclusion in the result set
			CopyPoints(0);
			CopyPoints(1);
			
			// node the input Geometries
			arg[0].ComputeSelfNodes(li, false);
			arg[1].ComputeSelfNodes(li, false);
			
			// compute intersections between edges of the two input geometries
			arg[0].ComputeEdgeIntersections(arg[1], li, true);
			
			EdgeCollection baseSplitEdges = new EdgeCollection();
			arg[0].ComputeSplitEdges(baseSplitEdges);
			arg[1].ComputeSplitEdges(baseSplitEdges);
//			EdgeCollection splitEdges = baseSplitEdges;
			// Add the noded edges to this result graph
			InsertUniqueEdges(baseSplitEdges);
			
			ComputeLabelsFromDepths();
			ReplaceCollapsedEdges();
			
			graph.AddEdges(edgeList.Edges);
			ComputeLabelling();

            LabelIncompleteNodes();
			
			// The ordering of building the result Geometries is important.
			// Areas must be built before lines, which must be built before points.
			// This is so that lines which are covered by areas are not included
			// explicitly, and similarly for points.
			FindResultAreaEdges(opCode);
			CancelDuplicateResultEdges();
			PolygonBuilder polyBuilder = new PolygonBuilder(geomFact);
			polyBuilder.Add(graph);
			resultPolyList = polyBuilder.Build();
			
			LineBuilder lineBuilder = new LineBuilder(this, geomFact, ptLocator);
			resultLineList = lineBuilder.Build(opCode);
			
			PointBuilder pointBuilder = new PointBuilder(this, geomFact);
			resultPointList = pointBuilder.Build(opCode);
			
			// gather the results from all calculations into a single Geometry for the result set
			resultGeom = ComputeGeometry(resultPointList, resultLineList, resultPolyList);
		}
コード例 #3
0
		public virtual Geometry Buffer(Geometry g, double distance)
		{
			PrecisionModel precisionModel = workingPrecisionModel;
			if (precisionModel == null)
				precisionModel = g.PrecisionModel;
			
			// factory must be the same as the one used by the input
			geomFact = g.Factory;
			
			OffsetCurveBuilder curveBuilder = 
                new OffsetCurveBuilder(precisionModel, quadrantSegments);
			curveBuilder.EndCapStyle = endCapStyle;

			OffsetCurveSetBuilder curveSetBuilder = 
                new OffsetCurveSetBuilder(g, distance, curveBuilder);
			
			ArrayList bufferSegStrList = curveSetBuilder.Curves;
			
			// short-circuit test
			if (bufferSegStrList.Count <= 0)
			{
				Geometry emptyGeom = 
                    geomFact.CreateGeometryCollection(new Geometry[0]);

				return emptyGeom;
			}
			
			ComputeNodedEdges(bufferSegStrList, precisionModel);
			graph = new PlanarGraph(new OverlayNodeFactory());
			graph.AddEdges(edgeList.Edges);
			
			IList subgraphList         = CreateSubgraphs(graph);
			PolygonBuilder polyBuilder = new PolygonBuilder(geomFact);
			
            BuildSubgraphs(subgraphList, polyBuilder);

			GeometryList resultPolyList = polyBuilder.Build();
			
			Geometry resultGeom = geomFact.BuildGeometry(resultPolyList);

			return resultGeom;
		}