コード例 #1
0
        public void TestMultipolygonDifference()
        {
            var mp1 = Reader.Read(@"MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))");
            var mp2 = Reader.Read(@"MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20)))");

            IGeometry diff = null;

            Assert.DoesNotThrow(() => diff = mp1.Difference(mp2));
            Assert.IsNotNull(diff);
            Console.WriteLine("1-2:\n{0}", diff.AsText());
            Assert.DoesNotThrow(() => diff = mp2.Difference(mp1));
            Assert.IsNotNull(diff);
            Console.WriteLine("2-1:\n{0}", diff.AsText());
        }
コード例 #2
0
        public void TestInvertedItalicNTSConforming()
        {
            var atb = new AffineTransformationBuilder(
                new Coordinate(0, 0), new Coordinate(50, 0), new Coordinate(0, 100),
                new Coordinate(0, 0), new Coordinate(50, 0), new Coordinate(20, 100));

            var geom = _wktReader.Read(NTS);

            //Apply italic effect
            geom = atb.GetTransformation().Transform(geom);
            Console.WriteLine(geom.AsText());

            IGeometry constraint = ((IPolygon)geom).GetInteriorRingN(0);

            constraint = geom.Factory.CreatePolygon((ILinearRing)constraint, null);
            constraint = ((IPolygon)constraint.Buffer(-1)).Shell;
            var coordinates = constraint.Coordinates;

            coordinates[coordinates.Length - 1].X -= 1e-7;
            coordinates[coordinates.Length - 1].Y -= 1e-7;

            constraint = geom.Factory.CreateLineString(coordinates);
            Console.WriteLine(constraint.AsText());

            //Setup
            var dtb = new ConformingDelaunayTriangulationBuilder {
                Constraints = constraint
            };

            dtb.SetSites(geom);
            var result = dtb.GetEdges(geom.Factory);

            Console.WriteLine(result.AsText());
        }
コード例 #3
0
        protected override byte[] Write(IGeometry gIn)
        {
            var writer = new GaiaGeoWriter();

            writer.HandleOrdinates = Ordinates;
            writer.UseCompressed   = Compressed;

            var b = writer.Write(gIn);

            using (SQLiteConnection conn = new SQLiteConnection("Data Source=\"" + Name + "\""))
            {
                conn.Open();
                using (SQLiteCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO \"nts_io_spatialite\" VALUES(@P1, @P3, @P2);";
                    SQLiteParameter p1 = new SQLiteParameter("P1", DbType.Int32)
                    {
                        Value = this.Counter
                    };
                    SQLiteParameter p2 = new SQLiteParameter("P2", DbType.String)
                    {
                        Value = gIn.AsText()
                    };
                    SQLiteParameter p3 = new SQLiteParameter("P3", DbType.Binary)
                    {
                        Value = b
                    };
                    cmd.Parameters.AddRange(new[] { p1, p2, p3 });
                    cmd.ExecuteNonQuery();
                }
            }
            return(b);
        }
コード例 #4
0
        public void TestInvertedNTSConforming()
        {
            IGeometry geom = _wktReader.Read(NTS);

            Console.WriteLine(geom.AsText());

            IGeometry constraint = ((IPolygon)geom).GetInteriorRingN(0);

            constraint = geom.Factory.CreatePolygon((ILinearRing)constraint, null);
            constraint = ((IPolygon)constraint.Buffer(-1)).Shell;
            Coordinate[] coordinates = constraint.Coordinates;
            coordinates[coordinates.Length - 1].X -= 1e-7;
            coordinates[coordinates.Length - 1].Y -= 1e-7;

            constraint = geom.Factory.CreateLineString(coordinates);
            Console.WriteLine(constraint.AsText());

            //Setup
            ConformingDelaunayTriangulationBuilder dtb = new ConformingDelaunayTriangulationBuilder {
                Constraints = constraint
            };

            dtb.SetSites(geom);
            IMultiLineString result = dtb.GetEdges(geom.Factory);

            Console.WriteLine(result.AsText());
        }
コード例 #5
0
        protected override void CheckEquality(IGeometry gIn, IGeometry gParsed, WKTWriter writer)
        {
            var res = gIn.EqualsExact(gParsed);

            if (res)
            {
                return;
            }

            if (Compressed)
            {
                var discreteHausdorffDistance =
                    Algorithm.Distance.DiscreteHausdorffDistance.Distance(gIn, gParsed);
                if (discreteHausdorffDistance > 0.05)
                {
                    Console.WriteLine();
                    Console.WriteLine(gIn.AsText());
                    Console.WriteLine(gParsed.AsText());
                    Console.WriteLine("DiscreteHausdorffDistance=" + discreteHausdorffDistance);
                }
                Assert.IsTrue(discreteHausdorffDistance < 0.001);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
コード例 #6
0
        protected override byte[] Write(IGeometry gIn)
        {
            var geoWriter = new MsSql2008GeographyWriter();
            var b         = geoWriter.WriteGeography(gIn);
            var b2        = geoWriter.Write(gIn);

            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO [nts_io_geography] VALUES(@P1, @P2, @P3);";
                    var p1 = new SqlParameter("P1", SqlDbType.Int)
                    {
                        SqlValue = Counter
                    };
                    var p2 = new SqlParameter("P2", SqlDbType.Text)
                    {
                        SqlValue = gIn.AsText()
                    };
                    var p3 = new SqlParameter("P3", SqlDbType.Udt)
                    {
                        UdtTypeName = "geography", SqlValue = b
                    };
                    cmd.Parameters.AddRange(new[] { p1, p2, p3 });
                    cmd.ExecuteNonQuery();
                }
            }

            return(b2);
        }
コード例 #7
0
        private static bool TestWktWkb(int number, IGeometryFactory factory, string wkt, string wkb)
        {
            WKTReader r       = new WKTReader(factory);
            IGeometry wktGeom = r.Read(wkt);
            WKBReader s       = new WKBReader(factory);
            IGeometry wkbGeom = s.Read(WKBReader.HexToBytes(wkb));

            try
            {
                Assert.AreEqual(wkb, WKBWriter.ToHex(wktGeom.AsBinary()), "wkb's don't match");
                Assert.IsTrue(DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9, number + ": DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9");
                if (!wktGeom.EqualsExact(wkbGeom))
                {
                    Assert.AreEqual(wkt, wktGeom.AsText(), number + ": wkt.Equals(wktGeom.AsText())");
                    var wktGeom2 = s.Read(wktGeom.AsBinary());
                    Assert.AreEqual(wkt, wktGeom2.AsText(), number + ": wkt.Equals(wktGeom2.AsText())");
                    var diff = wkbGeom.Difference(wktGeom);
                    Assert.IsTrue(false, number + ": wktGeom.EqualsExact(wkbGeom)\n" + diff.AsText());
                }
                return(false);
            }
            catch (AssertionException ex)
            {
                Console.WriteLine(ex.Message);
                return(true);
            }
        }
コード例 #8
0
        protected override byte[] Write(IGeometry gIn)
        {
            PostGisWriter pgWriter = new PostGisWriter();

            byte[] b = pgWriter.Write(gIn);
            using (NpgsqlConnection cn = new NpgsqlConnection(this.ConnectionString))
            {
                cn.Open();
                using (NpgsqlCommand cmd = cn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO \"nts_io_postgis_2d\" VALUES(@P1, @P2, @P3);";
                    NpgsqlParameter p1 = new NpgsqlParameter("P1", NpgsqlDbType.Integer)
                    {
                        NpgsqlValue = this.Counter
                    };
                    NpgsqlParameter p2 = new NpgsqlParameter("P2", NpgsqlDbType.Text)
                    {
                        NpgsqlValue = gIn.AsText()
                    };
                    NpgsqlParameter p3 = new NpgsqlParameter("P3", NpgsqlDbType.Bytea)
                    {
                        NpgsqlValue = b
                    };
                    cmd.Parameters.AddRange(new[] { p1, p2, p3 });
                    cmd.ExecuteNonQuery();
                }
            }

            return(b);
        }
コード例 #9
0
ファイル: PostGIS2.cs プロジェクト: ghq1254544150/_SharpMap
        public SharpMap.Data.FeatureDataTable QueryFeatures(IGeometry geom, double distance)
        {
            Collection <IGeometry> features = new Collection <IGeometry>();

            using (PgConnection conn = new PgConnection(_ConnectionString))
            {
                string strGeom = "GeomFromText('" + geom.AsText() + "')";
                if (this.SRID > 0)
                {
                    strGeom = "setSRID(" + strGeom + "," + this.SRID.ToString() + ")";
                }

                string strSQL = "SELECT * , AsBinary(" + this.GeometryColumn + ") As sharpmap_tempgeometry FROM " + this.Table + " WHERE ";

                if (!String.IsNullOrEmpty(_defintionQuery))
                {
                    strSQL += this.DefinitionQuery + " AND ";
                }

                strSQL += this.GeometryColumn + " && " + "buffer(" + strGeom + "," + distance.ToString(Map.numberFormat_EnUS) + ")";
                strSQL += " AND distance(" + this.GeometryColumn + ", " + strGeom + ")<" + distance.ToString(Map.numberFormat_EnUS);

                using (PgDataAdapter adapter = new PgDataAdapter(strSQL, conn))
                {
                    System.Data.DataSet ds = new System.Data.DataSet();
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            fdt.AddRow(fdr);
                        }
                        return(fdt);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
コード例 #10
0
        protected override byte[] Write(IGeometry gIn)
        {
            var geoWriter = new MsSql2008GeometryWriter();
            var b = geoWriter.WriteGeometry(gIn);
            var b2 = geoWriter.Write(gIn);
            using( var conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO [nts_io_geometry] VALUES(@P1, @P2, @P3);";
                    var p1 = new SqlParameter("P1", SqlDbType.Int) { SqlValue = Counter };
                    var p2 = new SqlParameter("P2", SqlDbType.Text) { SqlValue = gIn.AsText() };
                    var p3 = new SqlParameter("P3", SqlDbType.Udt) { UdtTypeName = "geometry", SqlValue = b };
                    cmd.Parameters.AddRange(new[] { p1, p2, p3 });
                    cmd.ExecuteNonQuery();

                    /*
                    p1.SqlValue = 100000 + Counter;
                    cmd.Parameters.Remove(p3);
                    p3 = new SqlParameter("P3", SqlDbType.Image) { SqlValue = b };
                    cmd.Parameters.Add(p3);
                    p3.SqlValue = b2;
                    cmd.ExecuteNonQuery();
                     */
                }

            }
            return b2;
        }
コード例 #11
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds)
        {
            //List<Geometry> features = new List<Geometry>();
            using (var conn = new SqlConnection(ConnectionString))
            {
                //TODO: Convert to SQL Server
                string strGeom = _spatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString() : "0");
                strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";

                string strSQL = "SELECT g.* , g." + GeometryColumn + ".STAsBinary() As sharpmap_tempgeometry FROM " + Table + " g " + BuildTableHints() + " WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += strGeom;

                string extraOptions = GetExtraOptions();
                if (!string.IsNullOrEmpty(extraOptions))
                {
                    strSQL += " " + extraOptions;
                }


                using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory);
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
コード例 #12
0
        public void LoadCountries(string path)
        {
            iso2Countries   = new Dictionary <string, Feature>();
            iso3Countries   = new Dictionary <string, Feature>();
            countryFeatures = new ArrayList();

            countriesDt = new System.Data.DataTable();

            GeometryFactory factory = new GeometryFactory();

            using (ShapefileDataReader reader = new ShapefileDataReader(path, factory))
            {
                foreach (var f in reader.DbaseHeader.Fields)
                {
                    countriesDt.Columns.Add(f.Name, f.Type);
                }
                var keyCol = countryDtKeyCandidates
                             .Intersect(countriesDt.Columns.OfType <System.Data.DataColumn>().Select(col => col.ColumnName))
                             .FirstOrDefault();
                if (keyCol != null)
                {
                    countriesDt.PrimaryKey = new System.Data.DataColumn[] { countriesDt.Columns[keyCol] };
                }
                countriesDt.Columns.Add("WKT", typeof(string));

                while (reader.Read())
                {
                    Feature         feature         = new Feature();
                    AttributesTable attributesTable = new AttributesTable();

                    string[]  keys     = new string[reader.DbaseHeader.NumFields];
                    IGeometry geometry = (Geometry)reader.Geometry;

                    System.Data.DataRow row = countriesDt.NewRow();
                    for (int i = 0; i < reader.DbaseHeader.NumFields; i++)
                    {
                        DbaseFieldDescriptor fldDescriptor = reader.DbaseHeader.Fields[i];
                        keys[i] = fldDescriptor.Name;
                        attributesTable.AddAttribute(fldDescriptor.Name, reader.GetValue(i));

                        row[i] = reader.GetValue(i);
                    }
                    row["WKT"] = geometry.AsText();
                    countriesDt.Rows.Add(row);
                    feature.Geometry   = geometry;
                    feature.Attributes = attributesTable;

                    if (feature.Attributes.Exists("ISO2") && feature.Attributes.Exists("ISO3"))
                    {
                        int index = countryFeatures.Add(feature);
                        var iso2  = (string)feature.Attributes["ISO2"];
                        var iso3  = (string)feature.Attributes["ISO3"];
                        iso2Countries.Add(iso2, feature);
                        iso3Countries.Add(iso3, feature);
                    }
                }
                reader.Close();
            }
        }
コード例 #13
0
ファイル: Oracle.cs プロジェクト: cugkgq/Project
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="fcs">FeatureCollectionSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet fcs, CancellationToken?cancellationToken = null)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                var strGeom = "MDSYS.SDO_GEOMETRY('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(Map.NumberFormatEnUs) : "NULL");

                strGeom = "SDO_RELATE(g." + GeometryColumn + ", " + strGeom +
                          ", 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'";

                var strSQL = "SELECT g.* , g." + GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry FROM " +
                             Table + " g WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += strGeom;
                var ds = new FeatureDataSet();

                using (var adapter = new OracleDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count <= 0)
                    {
                        return;
                    }

                    var fdt = new FeatureDataTable(ds.Tables[0]);
                    foreach (DataColumn col in ds.Tables[0].Columns)
                    {
                        if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                        {
                            fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                        }
                    }

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        var fdr = fdt.NewRow();
                        foreach (DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdr[col.ColumnName] = dr[col];
                            }
                        }
                        fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory);
                        fdt.AddRow(fdr);
                    }
                    fcs.Add(fdt);
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds)
        {
            List <IGeometry> features = new List <IGeometry>();

            using (Npgsql.NpgsqlConnection conn = new Npgsql.NpgsqlConnection(_ConnectionString))
            {
                string strGeom = "GeomFromText('" + geom.AsText() + "')";
                if (this.SRID > 0)
                {
                    strGeom = "setSRID(" + strGeom + "," + this.SRID.ToString() + ")";
                }

                string strSQL = "SELECT * , AsBinary(" + this.GeometryColumn + ") As sharpmap_tempgeometry FROM " + this.Table + " WHERE ";

                if (!String.IsNullOrEmpty(_defintionQuery))
                {
                    strSQL += this.DefinitionQuery + " AND ";
                }

                strSQL += this.GeometryColumn + " && " + strGeom + " AND distance(" + this.GeometryColumn + ", " + strGeom + ")<0";

                using (Npgsql.NpgsqlDataAdapter adapter = new Npgsql.NpgsqlDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
コード例 #15
0
        public static void Run()
        {
            //ExStart: TranslateGeometryFromWkb
            string path = Path.Combine(RunExamples.GetDataDir(), "WkbFile.wkb");

            byte[]    wkb      = File.ReadAllBytes(path);
            IGeometry geometry = Geometry.FromBinary(wkb);

            Console.WriteLine(geometry.AsText()); // LINESTRING (1.2 3.4, 5.6 7.8)
            //ExEnd: TranslateGeometryFromWkb
        }
コード例 #16
0
        private NtsGeometry ShiftPoly(NtsGeometry poly, int lon_shift)
        {
            IGeometry pGeom = poly.Geometry;

            Assert.True(pGeom.IsValid);
            //shift 180 to the right
            pGeom = (IGeometry)pGeom.Clone();
            pGeom.Apply(new CoordinateFilterAnonymousHelper(this, lon_shift));
            pGeom.GeometryChanged();
            Assert.False(pGeom.IsValid);
            return((NtsGeometry)ctx.ReadShapeFromWkt(pGeom.AsText()));
        }
コード例 #17
0
        public void ConstructEsa()
        {
            IEsaConstructBuilder builder = new EsaConstructBuilder(
                new ArcDerivation(),
                new LocationDerivation());

            IGeometry construct = builder.BuildEsa(100000, 35.000, 94.000);

            var value = construct.AsText();

            Assert.IsNotNull(value);
        }
コード例 #18
0
 private static void TestValid(IGeometry geom)
 {
     if (!geom.IsValid)
     {
         var ivop = new NetTopologySuite.Operation.Valid.IsValidOp(geom);
         if (!ivop.IsValid)
         {
             Console.WriteLine(geom.AsText());
             Console.Write(ivop.ValidationError);
         }
         Assert.True(false);
     }
 }
コード例 #19
0
 private static void TestValid(IGeometry geom)
 {
     if (!geom.IsValid)
     {
         var ivop = new NetTopologySuite.Operation.Valid.IsValidOp(geom);
         if (!ivop.IsValid)
         {
             Console.WriteLine(geom.AsText());
             Console.Write(ivop.ValidationError);
         }
         Assert.True(false);
     }
 }
コード例 #20
0
        public void GeomBinOpTest_Issue14_00_Simplified_WkbWkt()
        {
            string wktStr        = geometry0.AsText();
            var    wktReader     = new WKTReader();
            var    geometry0_bis = wktReader.Read(wktStr);

            byte[] test00_Geom0_WkbByteArray_bis = geometry0_bis.AsBinary();
            Assert.AreEqual(test00_Geom0_WkbByteArray.Length, test00_Geom0_WkbByteArray_bis.Length, "Different wkb array length.");
            for (int i = 0; i < test00_Geom0_WkbByteArray_bis.Length; i++)
            {
                Assert.AreEqual(test00_Geom0_WkbByteArray[i], test00_Geom0_WkbByteArray_bis[i], "Different wkb array element at index " + i + ".");
            }
        }
コード例 #21
0
        //public static IList<ObjectId> CheckValid(IList<ObjectId> objectIds)
        //{
        //    var result = IsValid(objectIds);
        //    System.Diagnostics.Trace.WriteLine(result.Count);
        //    return result.Keys.ToList();
        //}

        public static Dictionary <ObjectId, SingleTopologyError> CheckValid(IList <ObjectId> objectIds)
        {
            var errorDictionary = new Dictionary <ObjectId, SingleTopologyError>();

            if (!objectIds.Any())
            {
                return(errorDictionary);
            }

            var database = objectIds[0].Database;

            var geometries = new List <IGeometry>();

            using (var tr = database.TransactionManager.StartTransaction())
            {
                var reader = new DwgReader();
                foreach (ObjectId objectId in objectIds)
                {
                    if (!objectId.IsValid)
                    {
                        continue;
                    }

                    IGeometry geom = reader.ReadEntityAsGeometry(tr, objectId);
                    if (geom == null)
                    {
                        continue;
                    }

                    geometries.Add(geom);
                    if (!geom.IsValid)
                    {
                        var ivop = new IsValidOp(geom);
                        if (!ivop.IsValid)
                        {
                            Console.WriteLine(geom.AsText());
                            Console.Write(ivop.ValidationError);
                            int errorType = (int)ivop.ValidationError.ErrorType;
                            var point     = new Point3d(ivop.ValidationError.Coordinate.X, ivop.ValidationError.Coordinate.Y, 0);
                            var error     = new SingleTopologyError((SingleTopologyErrors)errorType, point);
                            errorDictionary.Add(objectId, error);
                        }
                    }
                }
                tr.Commit();
            }

            return(errorDictionary);
        }
コード例 #22
0
        public void check_difference_results_with_fixed_precision()
        {
            GeometryFactory precisionModel = new GeometryFactory(new PrecisionModel(100));
            WKTReader       reader         = new WKTReader(precisionModel);
            IGeometry       p1             = reader.Read(@"POLYGON ((504927.9 6228865.64, 504969.88 6228833.89, 504980.82 6228861.76, 504927.9 6228865.64))");
            IGeometry       p2             = reader.Read(@"POLYGON ((504927.9 6228865.64, 504951.14 6228848.06, 504957.42 6228863.47, 504927.9 6228865.64))");
            IGeometry       test           = p1.Difference(p2);

            Assert.That(test, Is.Not.Null);
            Assert.That(test.IsEmpty, Is.False);

            const string expected = @"POLYGON ((504927.9 6228865.64, 504980.82 6228861.76, 504969.88 6228833.89, 504951.14 6228848.06, 504957.42 6228863.47, 504927.9 6228865.64))";
            string       actual   = test.AsText();

            Assert.That(actual, Is.EqualTo(expected));
        }
コード例 #23
0
        public void InvalidPolygon()
        {
            var wpfGeom = Geometry.Parse("M12.6206216812134, 50.9294242858887L11.5450315475464, 49.8538360595703 10.4694414138794, 50.9294242858887 11.5450315475464, 52.0050163269043 12.6206216812134, 50.9294242858887z M11.5870275497437, 55.99609375L10.0783662796021, 54.487434387207 8.56970500946045, 55.99609375 10.0783662796021, 57.5047569274902 11.5870275497437, 55.99609375z M5.77836227416992, 54.9871711730957L3.80277156829834, 56.962760925293 5.77836227416992, 58.9383506774902 7.7539529800415, 56.962760925293 5.77836227416992, 54.9871711730957z M5.51891326904297, 51.7981262207031L5.5027756690979, 51.99609375 6.71169662475586, 53.2050170898438 7.92061805725098, 51.99609375 6.74462604522705, 50.7876129150391 6.88728761672974, 50.0960960388184 5.14503145217896, 48.3538398742676 3.40277552604675, 50.0960960388184 5.14503145217896, 51.8383522033691 5.51891326904297, 51.7981262207031z M8.37836647033691, 45.7541007995605L6.53637409210205, 47.5960960388184 8.37836647033691, 49.4380874633789 10.2203578948975, 47.5960960388184 8.37836647033691, 45.7541007995605z M1.5868661403656, 45.6459007263184L1.5868661403656, 76.6044692993164 37.3742637634277, 76.6044692993164 37.3742637634277, 45.6459007263184 1.5868661403656, 45.6459007263184z");

            WpfGeometryToImage(wpfGeom, "InvalidPolygon.png");
            var reader = new WpfGeometryReader(Geometries.Geometry.DefaultFactory, true);

            IGeometry ntsGeom = null;

            Assert.DoesNotThrow(() => ntsGeom = reader.Read(wpfGeom));
            Debug.WriteLine(ntsGeom.AsText());
            var isValidOp = new Operation.Valid.IsValidOp(ntsGeom);

            if (!isValidOp.IsValid)
            {
                Assert.IsTrue(false, isValidOp.ValidationError.ToString());
            }

            Assert.AreEqual(wpfGeom.GetArea(), ntsGeom.Area, 1e-5);
        }
コード例 #24
0
        public void OutOfMemoryPolygon()
        {
            var wpfGeom = Geometry.Parse("M0,5 L0,15 10,15 10,5 0,5 M0,0 L15,15 M5,0 L5,10 15,10 15,0 5,0");

            WpfGeometryToImage(wpfGeom, "OutOfMemory.png");
            var reader = new WpfGeometryReader(Geometries.Geometry.DefaultFactory, true);

            IGeometry ntsGeom = null;

            Assert.DoesNotThrow(() => ntsGeom = reader.Read(wpfGeom));
            Debug.WriteLine(ntsGeom.AsText());
            var isValidOp = new Operation.Valid.IsValidOp(ntsGeom);

            if (!isValidOp.IsValid)
            {
                Assert.IsTrue(false, isValidOp.ValidationError.ToString());
            }

            Assert.AreEqual(wpfGeom.GetArea(), ntsGeom.Area, 1e-5);
        }
コード例 #25
0
        protected override byte[] Write(IGeometry gIn)
        {
            PostGisWriter pgWriter = new PostGisWriter();
            byte[] b = pgWriter.Write(gIn);
            using (NpgsqlConnection cn = new NpgsqlConnection(this.ConnectionString))
            {
                cn.Open();
                using (NpgsqlCommand cmd = cn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO \"nts_io_postgis_2d\" VALUES(@P1, @P2, @P3);";
                    NpgsqlParameter p1 = new NpgsqlParameter("P1", NpgsqlDbType.Integer) {NpgsqlValue = this.Counter};
                    NpgsqlParameter p2 = new NpgsqlParameter("P2", NpgsqlDbType.Text) { NpgsqlValue = gIn.AsText() };
                    NpgsqlParameter p3 = new NpgsqlParameter("P3", NpgsqlDbType.Bytea) { NpgsqlValue = b };
                    cmd.Parameters.AddRange(new[] { p1, p2, p3 });
                    cmd.ExecuteNonQuery();
                }
            }

            return b;
        }
コード例 #26
0
        protected override void CheckEquality(IGeometry gIn, IGeometry gParsed, WKTWriter writer)
        {
            var res = gIn.EqualsExact(gParsed);
            if (res) return;

            if (Compressed)
            {
                var discreteHausdorffDistance =
                    Algorithm.Distance.DiscreteHausdorffDistance.Distance(gIn, gParsed);
                if (discreteHausdorffDistance > 0.05)
                {
                    Console.WriteLine();
                    Console.WriteLine(gIn.AsText());
                    Console.WriteLine(gParsed.AsText());
                    Console.WriteLine("DiscreteHausdorffDistance=" + discreteHausdorffDistance);
                }
                Assert.IsTrue(discreteHausdorffDistance < 0.001);
            }
            else
                Assert.IsTrue(false);
        }
コード例 #27
0
ファイル: PostGisTest.cs プロジェクト: yangkf1985/DotSpatial
        /// <summary>
        ///
        /// </summary>
        /// <param name="wkt"></param>
        /// <param name="srid"></param>
        private static void General(string wkt, int srid)
        {
            IGeometry geom     = wr.Read(wkt);
            string    parsed   = geom.AsText();
            IGeometry regeom   = wr.Read(parsed);
            string    reparsed = regeom.AsText();

            geom.SRID   = srid;
            regeom.SRID = srid;

            Assert.IsTrue(geom.Equals(regeom));
            Assert.AreEqual(parsed, reparsed);

            byte[] bytesB = new PostGisWriter(ByteOrder.BigEndian).Write(regeom);
            regeom = br.Read(bytesB);
            Assert.IsTrue(geom.Equals(regeom));

            byte[] bytesL = new PostGisWriter(ByteOrder.LittleEndian).Write(regeom);
            regeom = br.Read(bytesL);
            Assert.IsTrue(geom.Equals(regeom));
            Assert.AreEqual(bytesB.Length, bytesL.Length);
        }
コード例 #28
0
        public void check_difference_results_with_fixed_precision()
        {
            GeometryFactory precisionModel = new GeometryFactory(new PrecisionModel(100));
            WKTReader       reader         = new WKTReader(precisionModel);
            IGeometry       p1             = reader.Read(@"POLYGON ((504927.9 6228865.64, 504969.88 6228833.89, 504980.82 6228861.76, 504927.9 6228865.64))");
            IGeometry       p2             = reader.Read(@"POLYGON ((504927.9 6228865.64, 504951.14 6228848.06, 504957.42 6228863.47, 504927.9 6228865.64))");
            IGeometry       test           = p1.Difference(p2);

            Assert.That(test, Is.Not.Null);
            Assert.That(test.IsEmpty, Is.False);

            const string expected = @"POLYGON ((504927.9 6228865.64, 504980.82 6228861.76, 504969.88 6228833.89, 504951.14 6228848.06, 504957.42 6228863.47, 504927.9 6228865.64))";
            var          res      = reader.Read(expected);

            res.Normalize();
            test.Normalize();
            Console.WriteLine(test.AsText());
            Console.WriteLine(res.AsText());
            var hd   = new HausdorffSimilarityMeasure();
            var resD = hd.Measure(test, res);

            Assert.That(1 - resD, Is.LessThan(1e7));
        }
コード例 #29
0
        private void DoIntersection(IGeometryFactory factory)
        {
            WKTReader reader = new WKTReader(factory);

            IGeometry poly1 = reader.Read(Poly1Wkt);

            Assert.IsTrue(poly1.IsValid);
            Assert.IsTrue(poly1 is IPolygon);

            IGeometry poly2 = reader.Read(Poly2Wkt);

            Assert.IsTrue(poly2.IsValid);
            Assert.IsTrue(poly2 is IPolygon);

            IGeometry intersection = poly1.Intersection(poly2);

            Assert.IsNotNull(intersection);
            Assert.IsTrue(intersection.IsValid);

            string intersectionWKT = intersection.AsText();

            Console.WriteLine(intersectionWKT);
            Assert.AreEqual(ExpectedResult, intersectionWKT, "Intersection error: result not same as JTS");
        }
コード例 #30
0
        public void TestInvertedItalicNTS()
        {
            AffineTransformationBuilder atb = new AffineTransformationBuilder(
                new Coordinate(0, 0),
                new Coordinate(50, 0),
                new Coordinate(0, 100),
                new Coordinate(0, 0),
                new Coordinate(50, 0),
                new Coordinate(20, 100));

            IGeometry geom = _wktReader.Read(NTS);

            //Apply italic effect
            geom = atb.GetTransformation().Transform(geom);
            Console.WriteLine(geom.AsText());

            //Setup
            DelaunayTriangulationBuilder dtb = new DelaunayTriangulationBuilder();

            dtb.SetSites(geom);
            IMultiLineString result = dtb.GetEdges(geom.Factory);

            Console.WriteLine(result.AsText());
        }
コード例 #31
0
        protected override byte[] Write(IGeometry gIn)
        {
            var writer = new GaiaGeoWriter();
            writer.HandleOrdinates = Ordinates;
            writer.UseCompressed = Compressed;

            var b = writer.Write(gIn);
            using (SQLiteConnection conn = new SQLiteConnection("Data Source=\"" + Name + "\""))
            {
                conn.Open();
                using (SQLiteCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO \"nts_io_spatialite\" VALUES(@P1, @P3, @P2);";
                    SQLiteParameter p1 = new SQLiteParameter("P1", DbType.Int32) { Value = this.Counter };
                    SQLiteParameter p2 = new SQLiteParameter("P2", DbType.String) { Value = gIn.AsText() };
                    SQLiteParameter p3 = new SQLiteParameter("P3", DbType.Binary) { Value = b };
                    cmd.Parameters.AddRange(new[] { p1, p2, p3 });
                    cmd.ExecuteNonQuery();
                }
            }
            return b;
        }
コード例 #32
0
        /// <summary>
        /// 
        /// </summary>
        public override void Start()
        {
            IPoint pInterior = Factory.CreatePoint(new Coordinate(100, 100));
            IPoint pExterior = Factory.CreatePoint(new Coordinate(100, 101));

            try
            {
                Write(point.Area);                
                Write(point.Boundary);
                Write(point.BoundaryDimension);                                
                Write(point.Centroid);
                Write(point.Coordinate);
                Write(point.Coordinates);
                Write(point.CoordinateSequence);
                Write(point.Dimension);
                Write(point.Envelope);
                Write(point.EnvelopeInternal);
                Write(point.Factory);
                Write(point.InteriorPoint);
                Write(point.IsEmpty);
                Write(point.IsSimple);
                Write(point.IsValid);
                Write(point.Length);
                Write(point.NumPoints);
                Write(point.PrecisionModel);                          
                Write(point.X);
                Write(point.Y);                               

                Write(point.Contains(pInterior));
                Write(point.Contains(pExterior));

                Write(point.Buffer(10));
                Write(point.Buffer(10, BufferStyle.CapSquare));
                Write(point.Buffer(10, BufferStyle.CapButt));
                Write(point.Buffer(10, 20));                
                Write(point.Buffer(10, 20, BufferStyle.CapSquare));                
                Write(point.Buffer(10, 20, BufferStyle.CapButt)); 

                Write(point.Crosses(pInterior));
                Write(point.Crosses(pExterior));
                Write(point.Difference(pInterior));
                Write(point.Difference(pExterior));   
                Write(point.Disjoint(pInterior));
                Write(point.Disjoint(pExterior));
                Write(point.Equals(pInterior));
                Write(point.Equals(pExterior));
                Write(point.EqualsExact(pInterior));
                Write(point.EqualsExact(pExterior));
                Write(point.ConvexHull());
                Write(point.Intersection(pInterior)); 
                Write(point.Intersection(pExterior)); 
                Write(point.Intersects(pInterior));
                Write(point.Intersects(pExterior));
                Write(point.IsWithinDistance(pInterior, 0.001));
                Write(point.IsWithinDistance(pExterior, 0.001));                
                Write(point.Overlaps(pInterior));
                Write(point.Overlaps(pExterior));
                Write(point.SymmetricDifference(pInterior));
                Write(point.SymmetricDifference(pExterior));
                Write(point.ToString());
                Write(point.AsText());                
                Write(point.Touches(pInterior));
                Write(point.Touches(pExterior));
                Write(point.Union(pInterior));                 
                Write(point.Union(pExterior));         
                Write(point.Within(pInterior));                        
                Write(point.Within(pExterior));
                                
                string pointstring = "POINT (100.22 100.33)";
                string anotherpointstring = "POINT (12345 3654321)";
                IGeometry geom1 = Reader.Read(pointstring);
                Write(geom1.AsText());
                IGeometry geom2 = Reader.Read(anotherpointstring);
                Write(geom2.AsText());

                byte[] bytes = point.AsBinary();
                IGeometry test1 = new WKBReader().Read(bytes);
                Write(test1.ToString());
                
                bytes = Factory.CreatePoint(new Coordinate(Double.MinValue, Double.MinValue)).AsBinary();
                IGeometry testempty = new WKBReader().Read(bytes);
                Write(testempty);

                bytes = new GDBWriter().Write(geom1);
                test1 = new GDBReader().Read(bytes);
                Write(test1.ToString());                 
   
                // Test Empty Geometries
                Write(Point.Empty);
                Write(LineString.Empty);
                Write(Polygon.Empty);
                Write(MultiPoint.Empty);
                Write(MultiLineString.Empty);
                Write(MultiPolygon.Empty);
                Write(GeometryCollection.Empty);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }       
コード例 #33
0
        public static MgByteReader GetAgf(IGeometry geom)
        {
            MgGeometry mgeom = _wktRw.Read(geom.AsText());

            return(_agfRw.Write(mgeom));
        }
コード例 #34
0
ファイル: SqlServer2008.cs プロジェクト: lishxi/_SharpMap
       /// <summary>   
       /// Returns the features that intersects with 'geom'   
       /// </summary>   
       /// <param name="geom"></param>   
       /// <param name="ds">FeatureDataSet to fill data into</param>   
       protected override void OnExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds)   
       {   
           //List<Geometry> features = new List<Geometry>();   
           using (var conn = new SqlConnection(ConnectionString))   
           {   
               //TODO: Convert to SQL Server   
               string strGeom = _spatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

               strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString() : "0");
               strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";   
 
               string strSQL = "SELECT g.* , g." + GeometryColumn + ".STAsBinary() As sharpmap_tempgeometry FROM " + Table + " g " + BuildTableHints() + " WHERE ";   
 
               if (!String.IsNullOrEmpty(_definitionQuery))   
                   strSQL += DefinitionQuery + " AND ";   
 
               strSQL += strGeom;

               string extraOptions = GetExtraOptions();
               if (!string.IsNullOrEmpty(extraOptions))
                   strSQL += " " + extraOptions;
 
 
               using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))   
               {   
                   conn.Open();   
                   adapter.Fill(ds);   
                   conn.Close();   
                   if (ds.Tables.Count > 0)   
                   {   
                       FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);   
                       foreach (System.Data.DataColumn col in ds.Tables[0].Columns)   
                           if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")   
                               fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);   
                       foreach (System.Data.DataRow dr in ds.Tables[0].Rows)   
                       {   
                           FeatureDataRow fdr = fdt.NewRow();   
                           foreach (System.Data.DataColumn col in ds.Tables[0].Columns)   
                               if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")   
                                   fdr[col.ColumnName] = dr[col];
                           fdr.Geometry = Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory);   
                           fdt.AddRow(fdr);   
                       }   
                       ds.Tables.Add(fdt);   
                   }   
               }   
           }   
       }   
コード例 #35
0
ファイル: Oracle.cs プロジェクト: geobabbler/SharpMap
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="fcs">FeatureCollectionSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet fcs, CancellationToken? cancellationToken=null)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                var strGeom = "MDSYS.SDO_GEOMETRY('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(Map.NumberFormatEnUs) : "NULL");

                strGeom = "SDO_RELATE(g." + GeometryColumn + ", " + strGeom +
                          ", 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'";

                var strSQL = "SELECT g.* , g." + GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry FROM " +
                             Table + " g WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                    strSQL += DefinitionQuery + " AND ";

                strSQL += strGeom;
                var ds = new FeatureDataSet();

                using (var adapter = new OracleDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count <= 0)
                    {
                        return;
                    }
                    
                    var fdt = new FeatureDataTable(ds.Tables[0]);
                    foreach (DataColumn col in ds.Tables[0].Columns)
                    {
                        if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                        {
                            fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                        }
                    }
                    
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        var fdr = fdt.NewRow();
                        foreach (DataColumn col in ds.Tables[0].Columns)
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                fdr[col.ColumnName] = dr[col];
                        fdr.Geometry = GeometryFromWKB.Parse((byte[]) dr["sharpmap_tempgeometry"], Factory);
                        fdt.AddRow(fdr);
                    }
                    fcs.Add(fdt);
                }
            }
        }
コード例 #36
0
ファイル: PostGIS.cs プロジェクト: diegowald/intellitrack
		public SharpMap.Data.FeatureDataTable QueryFeatures(IGeometry geom, double distance)
		{
			//Collection<IGeometry> features = new Collection<IGeometry>();
			using (Npgsql.NpgsqlConnection conn = new Npgsql.NpgsqlConnection(_ConnectionString))
			{
				string strGeom = "GeomFromText('" + geom.AsText() + "')";
				if (this.SRID > 0)
					strGeom = "setSRID(" + strGeom + "," + this.SRID.ToString() + ")";

				string strSQL = "SELECT * , AsBinary(" + this.GeometryColumn + ") As sharpmap_tempgeometry FROM " + this.Table + " WHERE ";

				if (!String.IsNullOrEmpty(_defintionQuery))
					strSQL += this.DefinitionQuery + " AND ";

				strSQL += this.GeometryColumn + " && " + "buffer(" + strGeom + "," + distance.ToString(Map.numberFormat_EnUS) + ")";
				strSQL += " AND distance(" + this.GeometryColumn + ", " + strGeom + ")<" + distance.ToString(Map.numberFormat_EnUS);

				using (Npgsql.NpgsqlDataAdapter adapter = new Npgsql.NpgsqlDataAdapter(strSQL, conn))
				{
					System.Data.DataSet ds = new System.Data.DataSet();
					conn.Open();
					adapter.Fill(ds);
					conn.Close();
					if (ds.Tables.Count > 0)
					{
						FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
						foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
							if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
								fdt.Columns.Add(col.ColumnName,col.DataType,col.Expression);
						foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
						{
							SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();
							foreach(System.Data.DataColumn col in ds.Tables[0].Columns)
								if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
									fdr[col.ColumnName] = dr[col];
							fdr.Geometry = SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
							fdt.AddRow(fdr);								
						}
						return fdt;
					}
					else return null;
				}
			}
		}
コード例 #37
0
        public override void Start()
        {
            IPoint      interiorPoint = Factory.CreatePoint(new Coordinate(130, 150));
            IPoint      exteriorPoint = Factory.CreatePoint(new Coordinate(650, 1500));
            ILineString aLine         = Factory.CreateLineString(new Coordinate[] { new Coordinate(23, 32.2), new Coordinate(10, 222) });
            ILineString anotherLine   = Factory.CreateLineString(new Coordinate[] { new Coordinate(0, 1), new Coordinate(30, 30) });
            ILineString intersectLine = Factory.CreateLineString(new Coordinate[] { new Coordinate(0, 1), new Coordinate(300, 300) });

            try
            {
                Write(polygon.Area);
                Write(polygon.Boundary);
                Write(polygon.BoundaryDimension);
                Write(polygon.Centroid);
                Write(polygon.Coordinate);
                Write(polygon.Coordinates.Length);
                Write(polygon.Dimension);
                Write(polygon.Envelope);
                Write(polygon.EnvelopeInternal);
                Write(polygon.ExteriorRing);
                Write(polygon.InteriorPoint);
                Write(polygon.InteriorRings.Length);
                Write(polygon.IsEmpty);
                Write(polygon.IsSimple);
                Write(polygon.IsValid);
                Write(polygon.Length);
                Write(polygon.NumInteriorRings);
                Write(polygon.NumPoints);
                if (polygon.UserData != null)
                {
                    Write(polygon.UserData);
                }
                else
                {
                    Write("UserData null");
                }

                Write(polygon.Buffer(10));
                Write(polygon.Buffer(10, BufferStyle.CapButt));
                Write(polygon.Buffer(10, BufferStyle.CapSquare));
                Write(polygon.Buffer(10, 20));
                Write(polygon.Buffer(10, 20, BufferStyle.CapButt));
                Write(polygon.Buffer(10, 20, BufferStyle.CapSquare));
                Write(polygon.Contains(interiorPoint));
                Write(polygon.Contains(exteriorPoint));
                Write(polygon.Contains(aLine));
                Write(polygon.Contains(anotherLine));
                Write(polygon.Crosses(interiorPoint));
                Write(polygon.Crosses(exteriorPoint));
                Write(polygon.Crosses(aLine));
                Write(polygon.Crosses(anotherLine));
                Write(polygon.Difference(interiorPoint));
                Write(polygon.Difference(exteriorPoint));
                Write(polygon.Difference(aLine));
                Write(polygon.Difference(anotherLine));
                Write(polygon.Disjoint(interiorPoint));
                Write(polygon.Disjoint(exteriorPoint));
                Write(polygon.Disjoint(aLine));
                Write(polygon.Disjoint(anotherLine));
                Write(polygon.Distance(interiorPoint));
                Write(polygon.Distance(exteriorPoint));
                Write(polygon.Distance(aLine));
                Write(polygon.Distance(anotherLine));
                Write(polygon.Intersection(interiorPoint));
                Write(polygon.Intersection(exteriorPoint));
                Write(polygon.Intersection(aLine));
                Write(polygon.Intersection(anotherLine));
                Write(polygon.Intersects(interiorPoint));
                Write(polygon.Intersects(exteriorPoint));
                Write(polygon.Intersects(aLine));
                Write(polygon.Intersects(anotherLine));
                Write(polygon.IsWithinDistance(interiorPoint, 300));
                Write(polygon.IsWithinDistance(exteriorPoint, 300));
                Write(polygon.IsWithinDistance(aLine, 300));
                Write(polygon.IsWithinDistance(anotherLine, 300));
                Write(polygon.Overlaps(interiorPoint));
                Write(polygon.Overlaps(exteriorPoint));
                Write(polygon.Overlaps(aLine));
                Write(polygon.Overlaps(anotherLine));
                Write(polygon.Relate(interiorPoint));
                Write(polygon.Relate(exteriorPoint));
                Write(polygon.Relate(aLine));
                Write(polygon.Relate(anotherLine));
                Write(polygon.SymmetricDifference(interiorPoint));
                Write(polygon.SymmetricDifference(exteriorPoint));
                Write(polygon.SymmetricDifference(aLine));
                Write(polygon.SymmetricDifference(anotherLine));
                Write(polygon.ToString());
                Write(polygon.AsText());
                Write(polygon.Touches(interiorPoint));
                Write(polygon.Touches(exteriorPoint));
                Write(polygon.Touches(aLine));
                Write(polygon.Touches(anotherLine));
                Write(polygon.Union(interiorPoint));
                Write(polygon.Union(exteriorPoint));
                Write(polygon.Union(aLine));
                Write(polygon.Union(anotherLine));

                string    aPoly       = "POLYGON ((20 20, 100 20, 100 100, 20 100, 20 20))";
                string    anotherPoly = "POLYGON ((20 20, 100 20, 100 100, 20 100, 20 20), (50 50, 60 50, 60 60, 50 60, 50 50))";
                IGeometry geom1       = Reader.Read(aPoly);
                Write(geom1.AsText());
                IGeometry geom2 = Reader.Read(anotherPoly);
                Write(geom2.AsText());

                // ExpandToInclude tests
                Envelope envelope = new Envelope(0, 0, 0, 0);
                envelope.ExpandToInclude(geom1.EnvelopeInternal);
                envelope.ExpandToInclude(geom2.EnvelopeInternal);
                Write(envelope.ToString());

                // The polygon is not correctly ordered! Calling normalize we fix the problem...
                polygon.Normalize();

                byte[]    bytes = polygon.AsBinary();
                IGeometry test1 = new WKBReader().Read(bytes);
                Write(test1.ToString());

                bytes = new GDBWriter().Write(polygon);
                test1 = new GDBReader().Read(bytes);
                Write(test1.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #38
0
ファイル: OracleSpatial.cs プロジェクト: geobabbler/SharpMap
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet fcs, CancellationToken? cancellationToken=null)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                string strGeom = "MDSYS.SDO_GEOMETRY('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(Map.NumberFormatEnUs) : "NULL");

                strGeom = "SDO_RELATE(g." + GeometryColumn + ", " + strGeom +
                          ", 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'";

                string strSql = "SELECT * FROM " +
                                Table + " g WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                    strSql += DefinitionQuery + " AND ";

                strSql += strGeom;

                var ds = (DataSet) new FeatureDataSet();
                using (var adapter = new OracleDataAdapter(strSql, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (DataColumn col in ds.Tables[0].Columns)
                            if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0)
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            var fdr = fdt.NewRow();
                            foreach (DataColumn col in ds.Tables[0].Columns)
                                if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0)
                                    fdr[col.ColumnName] = dr[col];
                            var sdoGeometry = dr[GeometryColumn] as SdoGeometry;

                            if (sdoGeometry != null)
                            {
                                fdr.Geometry = sdoGeometry.AsGeometry();
                            }

                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
コード例 #39
0
        /// <summary>
        ///
        /// </summary>
        public override void Start()
        {
            IPoint      pointInLine  = Factory.CreatePoint(new Coordinate(20, 10));
            IPoint      pointOutLine = Factory.CreatePoint(new Coordinate(20, 31));
            ILineString aLine        = Factory.CreateLineString(new Coordinate[] { new Coordinate(23, 32.2), new Coordinate(922, 11) });
            ILineString anotherLine  = Factory.CreateLineString(new Coordinate[] { new Coordinate(0, 1), new Coordinate(30, 30) });

            try
            {
                Write(line.Area);
                Write(line.Boundary);
                Write(line.BoundaryDimension);
                Write(line.Centroid);
                Write(line.Coordinate);
                Write(line.Coordinates);
                Write(line.CoordinateSequence);
                Write(line.Dimension);
                Write(line.EndPoint);
                Write(line.Envelope);
                Write(line.EnvelopeInternal);
                Write(line.InteriorPoint);
                Write(line.IsClosed);
                Write(line.IsEmpty);
                Write(line.IsRing);
                Write(line.IsSimple);
                Write(line.IsValid);
                Write(line.Length);
                Write(line.NumPoints);
                Write(line.StartPoint);
                if (line.UserData != null)
                {
                    Write(line.UserData);
                }
                else
                {
                    Write("UserData null");
                }

                Write(line.Buffer(10));
                Write(line.Buffer(10, BufferStyle.CapButt));
                Write(line.Buffer(10, BufferStyle.CapSquare));
                Write(line.Buffer(10, 20));
                Write(line.Buffer(10, 20, BufferStyle.CapButt));
                Write(line.Buffer(10, 20, BufferStyle.CapSquare));
                Write(line.Contains(pointInLine));
                Write(line.Contains(pointOutLine));
                Write(line.Crosses(pointInLine));
                Write(line.Crosses(pointOutLine));
                Write(line.Difference(pointInLine));
                Write(line.Difference(pointOutLine));
                Write(line.Disjoint(pointInLine));
                Write(line.Disjoint(pointOutLine));
                Write(line.Distance(pointInLine));
                Write(line.Distance(pointOutLine));
                Write(line.Equals(line.Clone() as LineString));
                Write(line.EqualsExact(line.Clone() as LineString));
                Write(line.ConvexHull());
                Write(line.Intersection(pointInLine));
                Write(line.Intersection(pointOutLine));
                Write(line.Intersection(aLine));
                Write(line.Intersects(pointInLine));
                Write(line.Intersects(pointOutLine));
                Write(line.Intersects(aLine));
                Write(line.IsWithinDistance(pointOutLine, 2));
                Write(line.IsWithinDistance(pointOutLine, 222));
                Write(line.Overlaps(pointInLine));
                Write(line.Overlaps(pointOutLine));
                Write(line.Overlaps(aLine));
                Write(line.Overlaps(anotherLine));
                Write(line.Relate(pointInLine));
                Write(line.Relate(pointOutLine));
                Write(line.Relate(aLine));
                Write(line.Relate(anotherLine));
                Write(line.SymmetricDifference(pointInLine));
                Write(line.SymmetricDifference(pointOutLine));
                Write(line.SymmetricDifference(aLine));
                Write(line.SymmetricDifference(anotherLine));
                Write(line.ToString());
                Write(line.AsText());
                Write(line.Touches(pointInLine));
                Write(line.Touches(pointOutLine));
                Write(line.Touches(aLine));
                Write(line.Touches(anotherLine));
                Write(line.Union(pointInLine));
                Write(line.Union(pointOutLine));
                Write(line.Union(aLine));
                Write(line.Union(anotherLine));
                Write(line.Within(pointInLine));
                Write(line.Within(pointOutLine));
                Write(line.Within(aLine));
                Write(line.Within(anotherLine));

                string    linestring         = "LINESTRING (1.2 3.4, 5.6 7.8, 9.1 10.12)";
                string    anotherlinestringg = "LINESTRING (12345 3654321, 685 7777.945677, 782 111.1)";
                IGeometry geom1 = Reader.Read(linestring);
                Write(geom1.AsText());
                IGeometry geom2 = Reader.Read(anotherlinestringg);
                Write(geom2.AsText());

                byte[]    bytes = line.AsBinary();
                IGeometry test1 = new WKBReader().Read(bytes);
                Write(test1.ToString());

                bytes = new GDBWriter().Write(line);
                test1 = new GDBReader().Read(bytes);
                Write(test1.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #40
0
ファイル: Oracle.cs プロジェクト: lishxi/_SharpMap
		/// <summary>
		/// Returns the features that intersects with 'geom'
		/// </summary>
		/// <param name="geom"></param>
		/// <param name="ds">FeatureDataSet to fill data into</param>
		public void ExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds)
		{
			List<IGeometry> features = new List<IGeometry>();
			using (OracleConnection conn = new OracleConnection(_ConnectionString))
			{
				
                string strGeom = "MDSYS.SDO_GEOMETRY('" + geom.AsText() + "', #SRID#)";

                if (this.SRID > 0) {
                    strGeom = strGeom.Replace("#SRID#", this.SRID.ToString(Map.numberFormat_EnUS));
                } else {
                    strGeom = strGeom.Replace("#SRID#", "NULL");
                }

                strGeom = "SDO_RELATE(g." + this.GeometryColumn + ", " + strGeom + ", 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'";

                string strSQL = "SELECT g.* , g." + this.GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry FROM " + this.Table + " g WHERE ";

				if (!String.IsNullOrEmpty(_defintionQuery))
					strSQL += this.DefinitionQuery + " AND ";

				strSQL += strGeom;

				using (OracleDataAdapter adapter = new OracleDataAdapter(strSQL, conn))
				{
					conn.Open();
					adapter.Fill(ds);
					conn.Close();
					if (ds.Tables.Count > 0)
					{
						FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
						foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
							if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
								fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
						foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
						{
							SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();
							foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
								if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
									fdr[col.ColumnName] = dr[col];
							fdr.Geometry = SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
							fdt.AddRow(fdr);
						}
						ds.Tables.Add(fdt);
					}
				}
			}
		}
コード例 #41
0
ファイル: PostGIS2.cs プロジェクト: lishxi/_SharpMap
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds)
        {
            //List<IGeometry> features = new List<IGeometry>();
            using (PgConnection conn = new PgConnection(_ConnectionString))
            {
                string strGeom = "GeomFromText('" + geom.AsText() + "')";
                if (this.SRID > 0)
                    strGeom = "setSRID(" + strGeom + "," + this.SRID.ToString() + ")";

                string strSQL = "SELECT * , AsBinary(" + this.GeometryColumn + ") As sharpmap_tempgeometry FROM " + this.Table + " WHERE ";

                if (!String.IsNullOrEmpty(_defintionQuery))
                    strSQL += this.DefinitionQuery + " AND ";

                strSQL += this.GeometryColumn + " && " + strGeom + " AND distance(" + this.GeometryColumn + ", " + strGeom + ")<0";

                using (PgDataAdapter adapter = new PgDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                                if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                    fdr[col.ColumnName] = dr[col];
                            fdr.Geometry = SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }