Example #1
0
        public static ICoordinate ImageToWorld(Map map, double width, double height)
        {
            ICoordinate c1 = map.ImageToWorld(new PointF(0, 0));
            ICoordinate c2 = map.ImageToWorld(new PointF((float)width, (float)height));

            return(GeometryFactory.CreateCoordinate(Math.Abs(c1.X - c2.X), Math.Abs(c1.Y - c2.Y)));
        }
Example #2
0
 public void ZoomToBox_WithAspectCorrection()
 {
     SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(400, 200));
     map.ZoomToBox(GeometryFactory.CreateEnvelope(20, 10, 100, 180));
     Assert.AreEqual(GeometryFactory.CreateCoordinate(60, 95), map.Center);
     Assert.AreEqual(340, map.Zoom);
 }
Example #3
0
    private void TestMercator_1SP()
    {
        CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre);

        IHorizontalDatum            datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs   = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum,
                                                                                  PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                                                                                  new AxisInfo("Lat", AxisOrientationEnum.North));
        List <ProjectionParameter> parameters = new List <ProjectionParameter>();

        parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
        parameters.Add(new ProjectionParameter("central_meridian", 110));
        parameters.Add(new ProjectionParameter("scale_factor", 0.997));
        parameters.Add(new ProjectionParameter("false_easting", 3900000));
        parameters.Add(new ProjectionParameter("false_northing", 900000));
        IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

        ICoordinate pGeo  = GeometryFactory.CreateCoordinate(120, -3);
        ICoordinate pUtm  = GeometryFactory.CreateCoordinate(trans.MathTransform.Transform(new double[] { pGeo.X, pGeo.Y }));
        ICoordinate pGeo2 = GeometryFactory.CreateCoordinate(trans.MathTransform.Inverse().Transform(new double[] { pUtm.X, pUtm.Y }));

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, GeometryFactory.CreateCoordinate(5009726.58, 569150.82), pGeo2, "Mercator_1SP test");
    }
Example #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Set up the map. We use the method in the App_Code folder for initializing the map
        myMap = MapHelper.InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));
        //Set a gradient theme on the countries layer, based on Population density
        SharpMap.Rendering.Thematics.CustomTheme iTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle);
        SharpMap.Styles.VectorStyle defaultstyle        = new SharpMap.Styles.VectorStyle();
        defaultstyle.Fill   = Brushes.Gray;
        iTheme.DefaultStyle = defaultstyle;
        (myMap.Layers[0] as SharpMap.Layers.VectorLayer).Theme = iTheme;
        //Turn off the river layer and label-layers
        myMap.Layers[1].Enabled = false;
        myMap.Layers[3].Enabled = false;
        myMap.Layers[4].Enabled = false;

        if (Page.IsPostBack)
        {
            //Page is post back. Restore center and zoom-values from viewstate
            myMap.Center = (ICoordinate)ViewState["mapCenter"];
            myMap.Zoom   = (double)ViewState["mapZoom"];
        }
        else
        {
            //This is the initial view of the map. Zoom to the extents of the map:
            //myMap.ZoomToExtents();
            myMap.Center = GeometryFactory.CreateCoordinate(0, 0);
            myMap.Zoom   = 360;
            //Create the map
            GenerateMap();
        }
    }
Example #5
0
    private void TestAlbers()
    {
        CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot);

        IHorizontalDatum            datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs   = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum,
                                                                                  PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                                                                                  new AxisInfo("Lat", AxisOrientationEnum.North));
        List <ProjectionParameter> parameters = new List <ProjectionParameter>();

        parameters.Add(new ProjectionParameter("central_meridian", -96));
        parameters.Add(new ProjectionParameter("latitude_of_origin", 23));
        parameters.Add(new ProjectionParameter("standard_parallel_1", 29.5));
        parameters.Add(new ProjectionParameter("standard_parallel_2", 45.5));
        parameters.Add(new ProjectionParameter("false_easting", 0));
        parameters.Add(new ProjectionParameter("false_northing", 0));
        IProjection projection = cFac.CreateProjection("Albers Conical Equal Area", "albers", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Albers Conical Equal Area", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

        ICoordinate pGeo  = GeometryFactory.CreateCoordinate(-75, 35);
        ICoordinate pUtm  = GeometryFactory.CreateCoordinate(trans.MathTransform.Transform(new double[] { pGeo.X, pGeo.Y }));
        ICoordinate pGeo2 = GeometryFactory.CreateCoordinate(trans.MathTransform.Inverse().Transform(new double[] { pUtm.X, pUtm.Y }));

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, GeometryFactory.CreateCoordinate(1885472.7, 1535925), pGeo2, "Albers Conical Equal Area test");
    }
Example #6
0
    private void TestTransverseMercator()
    {
        CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Airy 1830", 6377563.396, 299.32496, LinearUnit.Metre);

        IHorizontalDatum            datum = cFac.CreateHorizontalDatum("Airy 1830", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs   = cFac.CreateGeographicCoordinateSystem("Airy 1830", AngularUnit.Degrees, datum,
                                                                                  PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                                                                                  new AxisInfo("Lat", AxisOrientationEnum.North));
        List <ProjectionParameter> parameters = new List <ProjectionParameter>();

        parameters.Add(new ProjectionParameter("latitude_of_origin", 49));
        parameters.Add(new ProjectionParameter("central_meridian", -2));
        parameters.Add(new ProjectionParameter("scale_factor", 0.9996012717));
        parameters.Add(new ProjectionParameter("false_easting", 400000));
        parameters.Add(new ProjectionParameter("false_northing", -100000));
        IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("OSGB 1936 / British National Grid", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

        ICoordinate pGeo  = GeometryFactory.CreateCoordinate(0.5, 50.5);
        ICoordinate pUtm  = GeometryFactory.CreateCoordinate(trans.MathTransform.Transform(new double[] { pGeo.X, pGeo.Y }));
        ICoordinate pGeo2 = GeometryFactory.CreateCoordinate(trans.MathTransform.Inverse().Transform(new double[] { pUtm.X, pUtm.Y }));

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, GeometryFactory.CreateCoordinate(577274.99, 69740.50), pGeo2, "Transverse Mercator test");
    }
Example #7
0
    private void TestMercator_2SP()
    {
        CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Krassowski 1940", 6378245.0, 298.3, LinearUnit.Metre);

        IHorizontalDatum            datum = cFac.CreateHorizontalDatum("Krassowski 1940", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs   = cFac.CreateGeographicCoordinateSystem("Krassowski 1940", AngularUnit.Degrees, datum,
                                                                                  PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                                                                                  new AxisInfo("Lat", AxisOrientationEnum.North));
        List <ProjectionParameter> parameters = new List <ProjectionParameter>();

        parameters.Add(new ProjectionParameter("latitude_of_origin", 42));
        parameters.Add(new ProjectionParameter("central_meridian", 51));
        parameters.Add(new ProjectionParameter("false_easting", 0));
        parameters.Add(new ProjectionParameter("false_northing", 0));
        IProjection projection = cFac.CreateProjection("Mercator_2SP", "Mercator_2SP", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Pulkovo 1942 / Mercator Caspian Sea", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

        ICoordinate pGeo  = GeometryFactory.CreateCoordinate(53, 53);
        ICoordinate pUtm  = GeometryFactory.CreateCoordinate(trans.MathTransform.Transform(new double[] { pGeo.X, pGeo.Y }));
        ICoordinate pGeo2 = GeometryFactory.CreateCoordinate(trans.MathTransform.Inverse().Transform(new double[] { pUtm.X, pUtm.Y }));

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, GeometryFactory.CreateCoordinate(165704.29, 5171848.07), pGeo2, "Mercator_2SP test");
    }
Example #8
0
    private void TestLambertConicConformal_2SP()
    {
        CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 20925832.16, 294.97470, LinearUnit.USSurveyFoot);

        IHorizontalDatum            datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs   = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum,
                                                                                  PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                                                                                  new AxisInfo("Lat", AxisOrientationEnum.North));
        List <ProjectionParameter> parameters = new List <ProjectionParameter>();

        parameters.Add(new ProjectionParameter("latitude_of_origin", 27.833333333));
        parameters.Add(new ProjectionParameter("central_meridian", -99));
        parameters.Add(new ProjectionParameter("standard_parallel_1", 28.3833333333));
        parameters.Add(new ProjectionParameter("standard_parallel_2", 30.2833333333));
        parameters.Add(new ProjectionParameter("false_easting", 2000000));
        parameters.Add(new ProjectionParameter("false_northing", 0));
        IProjection projection = cFac.CreateProjection("Lambert Conic Conformal (2SP)", "lambert_conformal_conic_2sp", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("NAD27 / Texas South Central", gcs, projection, LinearUnit.USSurveyFoot, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

        ICoordinate pGeo  = GeometryFactory.CreateCoordinate(-96, 28.5);
        ICoordinate pUtm  = GeometryFactory.CreateCoordinate(trans.MathTransform.Transform(new double[] { pGeo.X, pGeo.Y }));
        ICoordinate pGeo2 = GeometryFactory.CreateCoordinate(trans.MathTransform.Inverse().Transform(new double[] { pUtm.X, pUtm.Y }));

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, GeometryFactory.CreateCoordinate(2963503.91, 254759.80), pGeo2, "Lambert Conic Conformal 2SP test");
    }
Example #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Set up the map. We use the method in the App_Code folder for initializing the map and alter it afterwards
        myMap = MapHelper.InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));
        //Remove the river layer and label-layers
        myMap.Layers.RemoveAt(4);
        myMap.Layers.RemoveAt(3);
        myMap.Layers.RemoveAt(1);

        //Create Pie Layer
        SharpMap.Layers.VectorLayer pieLayer = new SharpMap.Layers.VectorLayer("Pie charts");
        pieLayer.DataSource = (myMap.Layers[0] as SharpMap.Layers.VectorLayer).DataSource;
        SharpMap.Rendering.Thematics.CustomTheme iTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle);
        pieLayer.Theme = iTheme;
        myMap.Layers.Add(pieLayer);

        if (Page.IsPostBack)
        {
            //Page is post back. Restore center and zoom-values from viewstate
            myMap.Center = (ICoordinate)ViewState["mapCenter"];
            myMap.Zoom   = (double)ViewState["mapZoom"];
        }
        else
        {
            //This is the initial view of the map. Zoom to the extents of the map:
            //myMap.ZoomToExtents();
            myMap.Center = GeometryFactory.CreateCoordinate(10, 50);
            myMap.Zoom   = 60;
            //Create the map
            GenerateMap();
        }
    }
Example #10
0
        private void generateLines(Collection <IGeometry> geometry, Random rndGen)
        {
            int numLines = rndGen.Next(10, 100);

            for (int lineIndex = 0; lineIndex < numLines; lineIndex++)
            {
                //LineString line = new LineString();
                List <ICoordinate> verticies = new List <ICoordinate>();

                int numVerticies = rndGen.Next(4, 15);

                ICoordinate lastPoint = GeometryFactory.CreateCoordinate(rndGen.NextDouble() * 1000, rndGen.NextDouble() * 1000);
                verticies.Add(lastPoint);

                for (int vertexIndex = 0; vertexIndex < numVerticies; vertexIndex++)
                {
                    ICoordinate nextPoint = GeometryFactory.CreateCoordinate(lastPoint.X + rndGen.Next(-50, 50), lastPoint.Y + rndGen.Next(-50, 50));
                    verticies.Add(nextPoint);

                    lastPoint = nextPoint;
                }

                geometry.Add(GeometryFactory.CreateLineString(verticies.ToArray()));
            }
        }
Example #11
0
 public void WorldToMap_DefaultMap_ReturnValue()
 {
     SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(500, 200));
     map.Center = GeometryFactory.CreateCoordinate(23, 34);
     map.Zoom   = 1000;
     System.Drawing.PointF p = map.WorldToImage(GeometryFactory.CreateCoordinate(8, 50));
     Assert.AreEqual(new System.Drawing.PointF(242.5f, 92), p);
 }
Example #12
0
 public void WorldToImage()
 {
     SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(1000, 500));
     map.Zoom   = 360;
     map.Center = GeometryFactory.CreateCoordinate(0, 0);
     Assert.AreEqual(new System.Drawing.PointF(500, 250), map.WorldToImage(GeometryFactory.CreateCoordinate(0, 0)));
     Assert.AreEqual(new System.Drawing.PointF(0, 0), map.WorldToImage(GeometryFactory.CreateCoordinate(-180, 90)));
     Assert.AreEqual(new System.Drawing.PointF(0, 500), map.WorldToImage(GeometryFactory.CreateCoordinate(-180, -90)));
     Assert.AreEqual(new System.Drawing.PointF(1000, 0), map.WorldToImage(GeometryFactory.CreateCoordinate(180, 90)));
     Assert.AreEqual(new System.Drawing.PointF(1000, 500), map.WorldToImage(GeometryFactory.CreateCoordinate(180, -90)));
 }
Example #13
0
 protected void Page_Load(object sender, EventArgs e)
 {
     ajaxMap.Map = MapHelper.InitializeMap(new System.Drawing.Size(10, 10));
     if (!Page.IsPostBack && !Page.IsCallback)
     {
         //Set up the map. We use the method in the App_Code folder for initializing the map
         ajaxMap.Map.Center = GeometryFactory.CreateCoordinate(0, 20);
         ajaxMap.FadeSpeed  = 10;
         ajaxMap.ZoomSpeed  = 10;
         ajaxMap.Map.Zoom   = 360;
     }
     ajaxMap.ResponseFormat = "maphandler.ashx?MAP=SimpleWorld&Width=[WIDTH]&Height=[HEIGHT]&Zoom=[ZOOM]&X=[X]&Y=[Y]";
 }
Example #14
0
 public void Initalize_MapInstance()
 {
     SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(2, 1));
     Assert.IsNotNull(map);
     Assert.IsNotNull(map.Layers);
     Assert.AreEqual(2f, map.Size.Width);
     Assert.AreEqual(1f, map.Size.Height);
     Assert.AreEqual(System.Drawing.Color.Transparent, map.BackColor);
     Assert.AreEqual(double.MaxValue, map.MaximumZoom);
     Assert.AreEqual(0, map.MinimumZoom);
     Assert.AreEqual(GeometryFactory.CreateCoordinate(0, 0), map.Center, "map.Center should be initialized to (0,0)");
     Assert.AreEqual(1, map.Zoom, "Map zoom should be initialized to 1.0");
 }
Example #15
0
        private void InsertCurvePoint(IFeature feature)
        {
            if (feature.Geometry is ILineString)
            {
                if (null == SnapResult)
                {
                    return;
                }
                List <ICoordinate> vertices = new List <ICoordinate>();

                int curvePointIndex = 0;
                for (int i = 0; i < feature.Geometry.Coordinates.Length; i++)
                {
                    vertices.Add(feature.Geometry.Coordinates[i]);
                    if (i == SnapResult.SnapIndexPrevious)
                    {
                        if ((!double.IsNaN(feature.Geometry.Coordinates[i].Z)) && (!double.IsNaN(feature.Geometry.Coordinates[i + 1].Z)))
                        {
                            double previous = Math.Sqrt(Math.Pow(SnapResult.Location.X - feature.Geometry.Coordinates[i].X, 2) +
                                                        Math.Pow(SnapResult.Location.Y - feature.Geometry.Coordinates[i].Y, 2));
                            double next = Math.Sqrt(Math.Pow(feature.Geometry.Coordinates[i + 1].X - SnapResult.Location.X, 2) +
                                                    Math.Pow(feature.Geometry.Coordinates[i + 1].Y - SnapResult.Location.Y, 2));
                            double fraction = previous / (previous + next);
                            double z        = feature.Geometry.Coordinates[i].Z +
                                              (feature.Geometry.Coordinates[i + 1].Z - feature.Geometry.Coordinates[i].Z) *
                                              fraction;
                            ICoordinate coordinate = GeometryFactory.CreateCoordinate(SnapResult.Location.X,
                                                                                      SnapResult.Location.Y);
                            coordinate.Z = z;
                            vertices.Add(coordinate);
                        }
                        else
                        {
                            vertices.Add(SnapResult.Location);
                        }
                        curvePointIndex = i + 1;
                    }

                    //NS: 2013-09-02, Jika convert curve masih gagal, maka gunakan curve tool dengan pembatasan,
                    // bahwa dalam 1 LineString maksimum 4 titik :)
                    //if (vertices.Count == 4)
                    //    MapControl.ActivateTool(MapControl.MoveTool);
                }
                ILineString newLineString = GeometryFactory.CreateLineString(vertices.ToArray());
                SelectTool  selectTool    = MapControl.SelectTool;
                //VectorLayer targetLayer = selectTool.MultiSelection[0].Layer;
                ILayer targetLayer = selectTool.FeatureEditors[0].Layer;
                feature.Geometry = newLineString;
                MapControl.SelectTool.Select(targetLayer, feature, curvePointIndex);
            }
        }
Example #16
0
 public override void OnDraw(Graphics graphics)
 {
     if (MultiSelectionMode == MultiSelectionMode.Lasso)
     {
         GraphicsHelper.DrawSelectionLasso(graphics, KeyExtendSelection ? Color.Magenta : Color.DeepSkyBlue, selectPoints.ToArray());
     }
     else
     {
         ICoordinate coordinate1 = GeometryFactory.CreateCoordinate(mouseDownLocation.X, mouseDownLocation.Y);
         ICoordinate coordinate2 = GeometryFactory.CreateCoordinate(WORLDPOSITION.X, WORLDPOSITION.Y);
         PointF      point1      = Map.WorldToImage(coordinate1);
         PointF      point2      = Map.WorldToImage(coordinate2);
         GraphicsHelper.DrawSelectionRectangle(graphics, KeyExtendSelection ? Color.Magenta : Color.DeepSkyBlue, point1, point2);
     }
 }
Example #17
0
        private IPolygon CreatePolygon(double left, double top, double right, double bottom)
        {
            var vertices = new List <ICoordinate>
            {
                GeometryFactory.CreateCoordinate(left, bottom),
                GeometryFactory.CreateCoordinate(right, bottom),
                GeometryFactory.CreateCoordinate(right, top),
                GeometryFactory.CreateCoordinate(left, top)
            };

            vertices.Add((ICoordinate)vertices[0].Clone());
            ILinearRing newLinearRing = GeometryFactory.CreateLinearRing(vertices.ToArray());

            return(GeometryFactory.CreatePolygon(newLinearRing, null));
        }
        private static IGeometry CreateCell(double offsetX, double offsetY, double extentX, double extentY)
        {
            var vertices = new List <ICoordinate>
            {
                GeometryFactory.CreateCoordinate(offsetX, offsetY),
                GeometryFactory.CreateCoordinate(offsetX + extentX, offsetY),
                GeometryFactory.CreateCoordinate(offsetX + extentX, offsetY + extentY),
                GeometryFactory.CreateCoordinate(offsetX, offsetY + extentY)
            };

            vertices.Add((ICoordinate)vertices[0].Clone());
            ILinearRing newLinearRing = new LinearRing(vertices.ToArray());

            return(new Polygon(newLinearRing));
        }
Example #19
0
        private void StartNewPolygon(ICoordinate worldPos)
        {
            List <ICoordinate> vertices = new List <ICoordinate>();

            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y));
            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y));
            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y));
            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y)); // ILinearRing must have > 3 points
            ILinearRing linearRing = GeometryFactory.CreateLinearRing(vertices.ToArray());
            IPolygon    polygon    = GeometryFactory.CreatePolygon(linearRing, null);

            FeatureProvider.Add(polygon);
            newObjectIndex = FeatureProvider.GetFeatureCount() - 1;

            // do not remove see newline MapControl.SelectTool.Select((VectorLayer)Layer, polygon, 1);
        }
Example #20
0
 public static void LineStringSnapFree(ref double minDistance, ref ISnapResult snapResult, ILineString lineString, ICoordinate worldPos)
 {
     for (int i = 1; i < lineString.Coordinates.Length; i++)
     {
         ICoordinate c1       = lineString.Coordinates[i - 1];
         ICoordinate c2       = lineString.Coordinates[i];
         double      distance = GeometryHelper.LinePointDistance(c1.X, c1.Y, c2.X, c2.Y,
                                                                 worldPos.X, worldPos.Y);
         if (distance >= minDistance)
         {
             continue;
         }
         minDistance = distance;
         snapResult  = new SnapResult(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y), null, lineString, i - 1, i);
     }
 }
Example #21
0
        public static IGeometry Scale(IGeometry geom, double scale)
        {
            var center = geom.Centroid;

            var coordinates = new List <ICoordinate>();

            foreach (var coordinate in geom.Coordinates)
            {
                var x = (scale * (coordinate.X - center.X)) + center.X;
                var y = (scale * (coordinate.Y - center.Y)) + center.Y;

                coordinates.Add(GeometryFactory.CreateCoordinate(x, y));
            }

            return(GeometryFactory.CreateLineString(coordinates.ToArray()));
        }
Example #22
0
        private void StartNewLine(ICoordinate worldPos)
        {
            List <ICoordinate> verticies = new List <ICoordinate>
            {
                GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y),
                GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y)
            };
            ILineString lineString = GeometryFactory.CreateLineString(verticies.ToArray());

            ((DataTableFeatureProvider)newLineLayer.DataSource).Clear();
            newLineLayer.DataSource.Add(lineString);

            adding            = true;
            ActualAutoCurve   = AutoCurve;
            ActualMinDistance = MinDistance;
        }
Example #23
0
        private void InsertCurvePoint(IFeature feature)
        {
            if (feature.Geometry is ILineString)
            {
                if (null == SnapResult)
                {
                    return;
                }
                List <ICoordinate> vertices = new List <ICoordinate>();

                int curvePointIndex = 0;
                for (int i = 0; i < feature.Geometry.Coordinates.Length; i++)
                {
                    vertices.Add(feature.Geometry.Coordinates[i]);
                    if (i == SnapResult.SnapIndexPrevious)
                    {
                        if ((!double.IsNaN(feature.Geometry.Coordinates[i].Z)) && (!double.IsNaN(feature.Geometry.Coordinates[i + 1].Z)))
                        {
                            double previous = Math.Sqrt(Math.Pow(SnapResult.Location.X - feature.Geometry.Coordinates[i].X, 2) +
                                                        Math.Pow(SnapResult.Location.Y - feature.Geometry.Coordinates[i].Y, 2));
                            double next = Math.Sqrt(Math.Pow(feature.Geometry.Coordinates[i + 1].X - SnapResult.Location.X, 2) +
                                                    Math.Pow(feature.Geometry.Coordinates[i + 1].Y - SnapResult.Location.Y, 2));
                            double fraction = previous / (previous + next);
                            double z        = feature.Geometry.Coordinates[i].Z +
                                              (feature.Geometry.Coordinates[i + 1].Z - feature.Geometry.Coordinates[i].Z) *
                                              fraction;
                            ICoordinate coordinate = GeometryFactory.CreateCoordinate(SnapResult.Location.X,
                                                                                      SnapResult.Location.Y);
                            coordinate.Z = z;
                            vertices.Add(coordinate);
                        }
                        else
                        {
                            vertices.Add(SnapResult.Location);
                        }
                        curvePointIndex = i + 1;
                    }
                }
                ILineString newLineString = GeometryFactory.CreateLineString(vertices.ToArray());
                SelectTool  selectTool    = MapControl.SelectTool;
                //VectorLayer targetLayer = selectTool.MultiSelection[0].Layer;
                ILayer targetLayer = selectTool.FeatureEditors[0].Layer;
                feature.Geometry = newLineString;
                MapControl.SelectTool.Select(targetLayer, feature, curvePointIndex);
            }
        }
Example #24
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Page.IsPostBack)
     {
         //Page is post back. Restore center and zoom-values from viewstate
         Center = (ICoordinate)ViewState["mapCenter"];
         Zoom   = (double)ViewState["mapZoom"];
     }
     else
     {
         //This is the initial view of the map.
         Center = GeometryFactory.CreateCoordinate(12, 48);
         Zoom   = 45;
         //Create the map
         GenerateMap();
     }
 }
Example #25
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Page.IsPostBack)
     {
         //Page is post back. Restore center and zoom-values from viewstate
         Center = (ICoordinate)ViewState["mapCenter"];
         Zoom   = (double)ViewState["mapZoom"];
     }
     else
     {
         Center = GeometryFactory.CreateCoordinate(0, 0);
         Zoom   = 360;
         //Create the map
         GenerateMap();
     }
     PrintWmsInfo();
 }
Example #26
0
    private void TestGeocentric()
    {
        CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("WGS84", AngularUnit.Degrees, HorizontalDatum.WGS84,
                                                                                PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North));
        IGeocentricCoordinateSystem geoccs = cFac.CreateGeocentricCoordinateSystem("WGS84 geocentric", gcs.HorizontalDatum, LinearUnit.Metre, PrimeMeridian.Greenwich);

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, geoccs);

        ICoordinate pGeo  = GeometryFactory.CreateCoordinate(2.12955, 53.80939444, 73);
        ICoordinate pGc   = GeometryFactory.CreateCoordinate(trans.MathTransform.Transform(new double[] { pGeo.X, pGeo.Y, pGeo.Z }));
        ICoordinate pGeo2 = GeometryFactory.CreateCoordinate(trans.MathTransform.Inverse().Transform(new double[] { pGc.X, pGc.Y, pGc.Z }));

        result.Text += PrintResultTable(gcs, geoccs, pGeo, pGc, GeometryFactory.CreateCoordinate(3771793.97, 140253.34, 5124304.35), pGeo2, "Geocentric test");

        return;
    }
Example #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ls"></param>
        /// <param name="transform"></param>
        /// <returns></returns>
        private static List <ICoordinate> ExtractCoordinates(ILineString ls, IMathTransform transform)
        {
            List <double[]> points =
                new List <double[]>(ls.NumPoints);

            foreach (ICoordinate c in ls.Coordinates)
            {
                points.Add(ToLightStruct(c.X, c.Y));
            }
            points = transform.TransformList(points);
            List <ICoordinate> coords = new List <ICoordinate>(points.Count);

            foreach (double[] p in points)
            {
                coords.Add(GeometryFactory.CreateCoordinate(p[0], p[1]));
            }
            return(coords);
        }
Example #28
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //Set up the map. We use the method in the App_Code folder for initializing the map
     myMap = InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));
     if (Page.IsPostBack)
     {
         //Page is post back. Restore center and zoom-values from viewstate
         myMap.Center = (ICoordinate)ViewState["mapCenter"];
         myMap.Zoom   = (double)ViewState["mapZoom"];
     }
     else
     {
         //This is the initial view of the map. Zoom to the extents of the map:
         myMap.Zoom   = 80;
         myMap.Center = GeometryFactory.CreateCoordinate(-95, 37);
         //Create the map
         GenerateMap();
     }
 }
Example #29
0
        private void generatePolygons(Collection <IGeometry> geometry, Random rndGen)
        {
            int numPolygons = rndGen.Next(10, 100);

            for (int polyIndex = 0; polyIndex < numPolygons; polyIndex++)
            {
                List <ICoordinate> verticies  = new List <ICoordinate>();
                ICoordinate        upperLeft  = GeometryFactory.CreateCoordinate(rndGen.NextDouble() * 1000, rndGen.NextDouble() * 1000);
                double             sideLength = rndGen.NextDouble() * 50;

                // Make a square
                verticies.Add(upperLeft);
                verticies.Add(GeometryFactory.CreateCoordinate(upperLeft.X + sideLength, upperLeft.Y));
                verticies.Add(GeometryFactory.CreateCoordinate(upperLeft.X + sideLength, upperLeft.Y - sideLength));
                verticies.Add(GeometryFactory.CreateCoordinate(upperLeft.X, upperLeft.Y - sideLength));

                geometry.Add(GeometryFactory.CreatePolygon(GeometryFactory.CreateLinearRing(verticies.ToArray()), null));
            }
        }
Example #30
0
 public void PolygonSnapFree(ref double minDistance, ref SnapResult snapResult, IPolygon polygon, ICoordinate worldPos)
 {
     for (int i = 1; i < polygon.Coordinates.Length; i++)
     {
         ICoordinate c1       = polygon.Coordinates[i - 1];
         ICoordinate c2       = polygon.Coordinates[i];
         double      distance = GeometryHelper.LinePointDistance(c1.X, c1.Y, c2.X, c2.Y, worldPos.X, worldPos.Y);
         if (distance >= minDistance)
         {
             continue;
         }
         minDistance = distance;
         snapResult  = new SnapResult(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y), null, null, polygon,
                                      i - 1, i)
         {
             Rule = this
         };
     }
 }