/// <summary> /// Get Envelope in external coordinates. /// </summary> /// <param name="precisionModel"></param> /// <param name="envelope"></param> /// <returns></returns> public static IEnvelope GetEnvelopeExternal(PrecisionModel precisionModel, IEnvelope envelope) { // get envelose in external coordinates Coordinate min = new Coordinate(envelope.Minimum.X, envelope.Minimum.Y); Coordinate max = new Coordinate(envelope.Maximum.X, envelope.Maximum.Y); // min = precisionModel.ToExternal(min); // max = precisionModel.ToExternal(max); Envelope bounds = new Envelope(min.X, max.X, min.Y, max.Y); return bounds; }
/// <summary> /// /// </summary> /// <param name="g0"></param> /// <param name="g1"></param> public GeometryGraphOperation(IGeometry g0, IGeometry g1) { // use the most precise model for the result if (g0.PrecisionModel.CompareTo(g1.PrecisionModel) >= 0) ComputationPrecision = new PrecisionModel(g0.PrecisionModel); else ComputationPrecision = new PrecisionModel(g1.PrecisionModel); arg = new GeometryGraph[2]; arg[0] = new GeometryGraph(0, g0); arg[1] = new GeometryGraph(1, g1); }
/// <summary> /// Imports a shapefile into a dababase Table. /// </summary> /// <remarks> /// This method assumes a Table has already been created in the database. /// Calling this method does not close the connection that is passed in. /// </remarks> /// <param name="filename"></param> /// <param name="connectionstring"></param> /// <param name="tableName"></param> /// <returns></returns> public static int ImportShapefile(string filename, string connectionstring, string tableName) { using (SqlConnection connection = new SqlConnection(connectionstring)) { int rowsAdded = -1; PrecisionModel pm = new PrecisionModel(); GeometryFactory geometryFactory = new GeometryFactory(pm, -1); DataTable shpDataTable = Shapefile.CreateDataTable(filename, tableName, geometryFactory); string createTableSql = CreateDbTable(shpDataTable, true); SqlCommand createTableCommand = new SqlCommand(createTableSql, connection); connection.Open(); createTableCommand.ExecuteNonQuery(); string sqlSelect = String.Format("select * from {0}", tableName); SqlDataAdapter selectCommand = new SqlDataAdapter(sqlSelect, connection); // use a data adaptor - saves donig the inserts ourselves SqlDataAdapter dataAdapter = new SqlDataAdapter(); dataAdapter.SelectCommand = new SqlCommand(sqlSelect, connection); SqlCommandBuilder custCB = new SqlCommandBuilder(dataAdapter); DataSet ds = new DataSet(); // fill dataset dataAdapter.Fill(ds, shpDataTable.TableName); // copy rows from our datatable to the empty Table in the DataSet int i = 0; foreach (DataRow row in shpDataTable.Rows) { DataRow newRow = ds.Tables[0].NewRow(); newRow.ItemArray = row.ItemArray; //gotcha! - new row still needs to be added to the Table. //NewRow() just creates a new row with the same schema as the Table. It does //not add it to the Table. ds.Tables[0].Rows.Add(newRow); i++; } // update all the rows in batch rowsAdded = dataAdapter.Update(ds, shpDataTable.TableName); int iRows = shpDataTable.Rows.Count; Debug.Assert(rowsAdded != iRows, String.Format("{0} of {1} rows were added to the database.", rowsAdded, shpDataTable.Rows.Count)); return rowsAdded; } }
/// <summary> /// /// </summary> /// <param name="coord"></param> /// <param name="exemplar"></param> /// <returns></returns> private static IPoint CreatePointFromInternalCoord(Coordinate coord, IGeometry exemplar) { Coordinate c = new Coordinate(coord); PrecisionModel prc = new PrecisionModel(exemplar.PrecisionModel); prc.MakePrecise(c); return exemplar.Factory.CreatePoint(c); }
/// <summary> /// /// </summary> /// <param name="pm"></param> public SimpleGeometryPrecisionReducer(PrecisionModel pm) { _newPrecisionModel = pm; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleSnapRounder"/> class. /// </summary> /// <param name="pm">The <see cref="PrecisionModel" /> to use.</param> public SimpleSnapRounder(PrecisionModel pm) { _li = new RobustLineIntersector(); _li.PrecisionModel = pm; _scaleFactor = pm.Scale; }
/// <summary> /// Constructs a GeometryFactory that generates Geometries having the given /// <c>PrecisionModel</c> and spatial-reference ID, and the default CoordinateSequence /// implementation. /// </summary> /// <param name="precisionModel">The PrecisionModel to use.</param> /// <param name="srid">The SRID to use.</param> public GeometryFactory(PrecisionModel precisionModel, int srid) : this(precisionModel, srid, GetDefaultCoordinateSequenceFactory()) { }
/// <summary> /// Constructs a GeometryFactory pertaining to a specific _coordinateSequenceFactory /// using any valid IGeometryFactory and ICoordinateSequenceFactory interface /// </summary> /// <param name="gf">An IGeometryFactory Interface</param> /// <param name="coordinateSequenceFactory">An ICoordianteSequenceFactory interface</param> public GeometryFactory(IGeometryFactory gf, ICoordinateSequenceFactory coordinateSequenceFactory) { _precisionModel = new PrecisionModel(gf.PrecisionModel); _coordinateSequenceFactory = coordinateSequenceFactory; _srid = gf.SRID; }
/// <summary> /// /// </summary> /// <param name="g"></param> /// <param name="distance"></param> /// <returns></returns> public IGeometry Buffer(IGeometry g, double distance) { PrecisionModel precisionModel = workingPrecisionModel; if (precisionModel == null) precisionModel = new 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); IList bufferSegStrList = curveSetBuilder.GetCurves(); // short-circuit test if (bufferSegStrList.Count <= 0) { IGeometry 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); IList resultPolyList = polyBuilder.Polygons; IGeometry resultGeom = geomFact.BuildGeometry(resultPolyList); return resultGeom; }
/// <summary> /// Constructs a GeometryFactory that generates Geometries having the given /// PrecisionModel, spatial-reference ID, and CoordinateSequence implementation. /// </summary> /// <param name="precisionModel"></param> /// <param name="srid"></param> /// <param name="coordinateSequenceFactory"></param> public GeometryFactory(PrecisionModel precisionModel, int srid, ICoordinateSequenceFactory coordinateSequenceFactory) { _precisionModel = precisionModel; _coordinateSequenceFactory = coordinateSequenceFactory; _srid = srid; }
/// <summary> /// Initializes a new instance of the <see cref="IteratedNoder"/> class. /// </summary> /// <param name="pm"></param> public IteratedNoder(PrecisionModel pm) { li = new RobustLineIntersector(); li.PrecisionModel = pm; }
/// <summary> /// /// </summary> /// <param name="g0"></param> public GeometryGraphOperation(IGeometry g0) { ComputationPrecision = new PrecisionModel(g0.PrecisionModel); arg = new GeometryGraph[1]; arg[0] = new GeometryGraph(0, g0);; }
/// <summary> /// Creates the <c>NumberFormatInfo</c> used to write <c>double</c>s /// with a sufficient number of decimal places. /// </summary> /// <param name="precisionModel"> /// The <c>PrecisionModel</c> used to determine /// the number of decimal places to write. /// </param> /// <returns> /// A <c>NumberFormatInfo</c> that write <c>double</c> /// s without scientific notation. /// </returns> private static NumberFormatInfo CreateFormatter(PrecisionModel precisionModel) { // the default number of decimal places is 16, which is sufficient // to accomodate the maximum precision of a double. int decimalPlaces = precisionModel.MaximumSignificantDigits; // specify decimal separator explicitly to avoid problems in other locales NumberFormatInfo nfi = new NumberFormatInfo(); nfi.NumberDecimalSeparator = "."; nfi.NumberDecimalDigits = decimalPlaces; nfi.NumberGroupSeparator = String.Empty; nfi.NumberGroupSizes = new int[] { }; return nfi; }
/// <summary> /// /// </summary> /// <param name="bufferSegStrList"></param> /// <param name="precisionModel"></param> private void ComputeNodedEdges(IList bufferSegStrList, PrecisionModel precisionModel) { INoder noder = GetNoder(precisionModel); noder.ComputeNodes(bufferSegStrList); IList nodedSegStrings = noder.GetNodedSubstrings(); foreach(object obj in nodedSegStrings) { SegmentString segStr = (SegmentString)obj; Label oldLabel = (Label)segStr.Data; Edge edge = new Edge(segStr.Coordinates, new Label(oldLabel)); InsertEdge(edge); } }
/// <summary> /// /// </summary> /// <param name="precisionModel"></param> /// <returns></returns> private INoder GetNoder(PrecisionModel precisionModel) { if (workingNoder != null) return workingNoder; // otherwise use a fast (but non-robust) noder LineIntersector li = new RobustLineIntersector(); li.PrecisionModel = precisionModel; MCIndexNoder noder = new MCIndexNoder(new IntersectionAdder(li)); return noder; }
/// <summary> /// Constructs a GeometryFactory object from any valid IGeometryFactory interface /// </summary> /// <param name="gf"></param> public GeometryFactory(IGeometryFactory gf) { _precisionModel = new PrecisionModel(gf.PrecisionModel); _coordinateSequenceFactory = GetDefaultCoordinateSequenceFactory(); _srid = gf.SRID; }
/// <summary> /// /// </summary> /// <param name="precisionDigits"></param> private void BufferFixedPrecision(int precisionDigits) { double sizeBasedScaleFactor = PrecisionScaleFactor(argGeom, distance, precisionDigits); PrecisionModel fixedPM = new PrecisionModel(sizeBasedScaleFactor); // don't change the precision model of the Geometry, just reduce the precision SimpleGeometryPrecisionReducer reducer = new SimpleGeometryPrecisionReducer(fixedPM); IGeometry reducedGeom = reducer.Reduce(argGeom); BufferBuilder bufBuilder = new BufferBuilder(); bufBuilder.WorkingPrecisionModel = fixedPM; bufBuilder.QuadrantSegments = quadrantSegments; // this may throw an exception, if robustness errors are encountered resultGeometry = bufBuilder.Buffer(reducedGeom, distance); }
/// <summary> /// Copy constructor to create a new <c>PrecisionModel</c> /// from an existing one. /// </summary> /// <param name="pm"></param> public PrecisionModel(PrecisionModel pm) { modelType = pm.modelType; scale = pm.scale; }