public virtual void  Intersection(string wktA, string wktB, PrecisionModel pm)
		{
			Console.WriteLine("Running example using Precision Model = " + pm);
			GeometryFactory fact = new GeometryFactory(pm);
			WKTReader wktRdr = new WKTReader(fact);
			
			IGeometry A = wktRdr.Read(wktA);
			IGeometry B = wktRdr.Read(wktB);
			IGeometry C = A.Intersection(B);
			
			Console.WriteLine("A intersection B = " + C);
		}
Beispiel #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="precisionDigits"></param>
        private void BufferReducedPrecision(int precisionDigits)
        {
            var sizeBasedScaleFactor = PrecisionScaleFactor(argGeom, distance, precisionDigits);
            // Debug.WriteLine(String.Format("recomputing with precision scale factor = {0}", sizeBasedScaleFactor));

            IPrecisionModel fixedPM = new PrecisionModel(sizeBasedScaleFactor);
            BufferFixedPrecision(fixedPM);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MCIndexSnapRounder"/> class.
 /// </summary>
 /// <param name="pm">The <see cref="PrecisionModel" /> to use.</param>
 public MCIndexSnapRounder(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()) { }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NtsProvider"/> class
 /// using the given <paramref name="precisionModel"/>.
 /// </summary>
 /// <param name="precisionModel">
 /// The <see cref="GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel"/>
 /// to use for define the precision of the geometry operations.
 /// </param>
 /// <seealso cref="PrecisionModels"/>
 /// <seealso cref="GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory"/>
 protected internal NtsProvider(GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel precisionModel)
 {
     geometryFactory = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(precisionModel);
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NtsProvider"/> class
 /// from another <see cref="SharpMap.Data.Providers.IFeatureProvider" />.
 /// </summary>
 /// <param name="provider">
 /// The base <see cref="SharpMap.Data.Providers.IFeatureProvider"/>
 /// from witch initialize the <see cref="NtsProvider"/> instance.
 /// </param>
 /// <param name="operation">
 /// The <see cref="GeometryOperationDelegate"/> to apply
 /// to all geometry elements in the <paramref name="provider"/>.
 /// </param>
 /// <param name="precisionModel">
 /// The <see cref="GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel"/>
 /// to use for define the precision of the geometry operations.
 /// </param>
 /// <seealso cref="PrecisionModels"/>
 /// <seealso cref="GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory"/>
 public NtsProvider(SharpMap.Data.Providers.IFeatureProvider provider, GeometryOperationDelegate operation,
                    GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel precisionModel) : this(provider, precisionModel)
 {
     operation(features);
 }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NtsProvider"/> class
 /// from another <see cref="SharpMap.Data.Providers.IFeatureProvider" />.
 /// </summary>
 /// <param name="provider">
 /// The base <see cref="SharpMap.Data.Providers.IFeatureProvider"/>
 /// from witch initialize the <see cref="NtsProvider"/> instance.
 /// </param>
 /// <param name="precisionModel">
 /// The <see cref="GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel"/>
 /// to use for define the precision of the geometry operations.
 /// </param>
 /// <seealso cref="PrecisionModels"/>
 /// <seealso cref="GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory"/>
 public NtsProvider(SharpMap.Data.Providers.IFeatureProvider provider,
                    GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel precisionModel) : this(precisionModel)
 {
     BuildFromProvider(provider);
 }
Beispiel #8
0
 /// <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())
 {
 }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:NtsProvider"/> class
 /// using the given <paramref name="precisionModel"/>.
 /// </summary>
 /// <param name="precisionModel">
 /// The <see cref="GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel"/>  
 /// to use for define the precision of the geometry operations.
 /// </param>
 /// <seealso cref="GisSharpBlog.NetTopologySuite.Geometries.PrecisionModels"/>
 /// <seealso cref="GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory"/>
 protected internal NtsProvider(PrecisionModel precisionModel)
 {
     geometryFactory = new GeometryFactory(precisionModel);
 }
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:NtsProvider"/> class
 /// from another <see cref="SharpMap.Data.Providers.IProvider" />.
 /// </summary>
 /// <param name="provider">
 /// The base <see cref="SharpMap.Data.Providers.IProvider"/> 
 /// from witch initialize the <see cref="NtsProvider"/> instance.
 /// </param>
 /// <param name="operation">
 /// The <see cref="GeometryOperationDelegate"/> to apply 
 /// to all geometry elements in the <paramref name="provider"/>.
 /// </param>         
 /// <param name="precisionModel">
 /// The <see cref="GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel"/>  
 /// to use for define the precision of the geometry operations.
 /// </param>
 /// <seealso cref="GisSharpBlog.NetTopologySuite.Geometries.PrecisionModels"/> 
 /// <seealso cref="GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory"/>
 public NtsProvider(IProvider provider, GeometryOperationDelegate operation,
                    PrecisionModel precisionModel)
     : this(provider, precisionModel)
 {
     operation(features);
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:NtsProvider"/> class
 /// from another <see cref="SharpMap.Data.Providers.IProvider" />.
 /// </summary>
 /// <param name="provider">
 /// The base <see cref="SharpMap.Data.Providers.IProvider"/> 
 /// from witch initialize the <see cref="NtsProvider"/> instance.
 /// </param>
 /// <param name="precisionModel">
 /// The <see cref="GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel"/>  
 /// to use for define the precision of the geometry operations.
 /// </param>
 /// <seealso cref="GisSharpBlog.NetTopologySuite.Geometries.PrecisionModels"/>     
 /// <seealso cref="GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory"/>
 public NtsProvider(IProvider provider,
                    PrecisionModel precisionModel)
     : this(precisionModel)
 {
     BuildFromProvider(provider);
 }
Beispiel #12
0
        public bool LoadFile(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new ArgumentException(fileName, 
                    "The file does not exits or the 'fileName' is not valid.");
            }

            try
            {
                XmlDocument xmldoc = new XmlDocument();

                xmldoc.Load(fileName);

                XmlElement root = xmldoc.DocumentElement;

                // Retrieve the "desc" tag, if any.
                XmlNode desc = root["desc"];
                string strTestDescription = String.Empty;
                if (desc != null && desc.InnerText.Length > 0)
                {
                    strTestDescription = desc.InnerText;
                }
                else
                {
                    strTestDescription = Path.GetFileNameWithoutExtension(fileName);
                }

                // Retrieve the "workspace", if any.
                XmlNode workspace = root["workspace"];
                if (workspace != null)
                {  
                    XmlAttributeCollection workspaceAttributes = workspace.Attributes;
                    if (workspaceAttributes != null && workspaceAttributes.Count > 0)
                    {
                        m_strTestWorkspace = workspaceAttributes["dir"].InnerText;
                    }
                }

                // Retrieve the "tolerance" attribute, if any.
                XmlNode tolerance = root["tolerance"];

                double dTolerance = 0.0;
                if (tolerance != null)
                {
                    string strTolerance = tolerance.InnerText;
                    try
                    {
                        dTolerance = Double.Parse(strTolerance, GetNumberFormatInfo());
                    }
                    catch (Exception ex)
                    {
                        XmlTestExceptionManager.Publish(ex);
                    }
                }

                // Retrieve the precisionName" tag, if any.
                PrecisionModel pm = null;
                XmlNode precision = root["precisionModel"];
                if (precision != null)
                {
                    XmlAttributeCollection precisionAttributes = precision.Attributes;
                    if (precisionAttributes != null && precisionAttributes.Count > 0)
                    {

                        XmlAttribute attribute = precisionAttributes["type"];
                        if (attribute != null)
                        {
                            string strPrecision = attribute.InnerText;

                            if (strPrecision == "FIXED" && precisionAttributes.Count == 4)
                            {
                                try
                                {
                                    double scale   =
                                        Double.Parse(precisionAttributes["scale"].InnerText, GetNumberFormatInfo());
                                    double offsetx =
                                        Double.Parse(precisionAttributes["offsetx"].InnerText, GetNumberFormatInfo());
                                    double offsety =
                                        Double.Parse(precisionAttributes["offsety"].InnerText, GetNumberFormatInfo());

                                    pm = new PrecisionModel(scale);
                                }
                                catch (Exception ex)
                                {
                                    XmlTestExceptionManager.Publish(ex);
                                }
                            }
                            else
                            {
                                pm = new PrecisionModel();
                            }
                        }
                        else
                        {
                            if (precisionAttributes.Count == 3)
                            {
                                double scale   =
                                    Double.Parse(precisionAttributes["scale"].InnerText, GetNumberFormatInfo());
                                double offsetx =
                                    Double.Parse(precisionAttributes["offsetx"].InnerText, GetNumberFormatInfo());
                                double offsety =
                                    Double.Parse(precisionAttributes["offsety"].InnerText, GetNumberFormatInfo());
 
                                pm = new PrecisionModel(scale);
                            }
                        }
                   }
                }

                if (pm == null)
                {
                    pm = new PrecisionModel();
                }
                m_objFactory   = new XmlTestFactory(pm);
                m_listCurTests = new XmlTestCollection();

                m_listCurTests.Name = strTestDescription;

                // Now, handle the "case" nodes
                XmlNodeList elemList = xmldoc.GetElementsByTagName("case");
                for (int i = 0; i < elemList.Count; i++)
                {   
                    ParseCaseNode(elemList[i], dTolerance);
                }

                m_listarrTests.Add(m_listCurTests);

                return true;
            }
            catch (Exception ex)
            {
                XmlTestExceptionManager.Publish(ex);

                return false;
            }
        }
Beispiel #13
0
 /// <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;
 }
Beispiel #14
0
		/// <summary>
		/// Imports a shapefile into a database table.
		/// </summary>
		/// <remarks>
		/// This method assumes a table has already been crated 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 = 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> 
 /// 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;
 }
        public XmlTestFactory(PrecisionModel pm)
		{
            m_objGeometryFactory = new GeometryFactory(pm);
            m_objReader = new WKTReader(m_objGeometryFactory);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pm"></param>
 public SimpleGeometryPrecisionReducer(PrecisionModel pm)
 {
     newPrecisionModel = pm;
 }
Beispiel #18
0
 /// <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;
 }