Beispiel #1
0
        private void oneshotCallbackToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MgGeometryFactory geomFact = new MgGeometryFactory();

            mapViewer.DigitizePoint((x, y) => {
                MgCoordinate coord = geomFact.CreateCoordinateXY(x, y);
                MgPoint pt         = geomFact.CreatePoint(coord);

                mapViewer.SelectByGeometry(pt, -1, (selection) => {
                    if (selection == null)
                    {
                        MessageBox.Show("No selected features");
                        return;
                    }
                    else
                    {
                        MgReadOnlyLayerCollection layers = selection.GetLayers();
                        if (layers != null)
                        {
                            StringBuilder sb = new StringBuilder("Selection summary:");
                            for (int i = 0; i < layers.GetCount(); i++)
                            {
                                MgLayerBase lyr = layers.GetItem(i);
                                sb.Append(Environment.NewLine + lyr.GetName() + ": " + selection.GetSelectedFeaturesCount(lyr, lyr.GetFeatureClassName()));
                            }
                            MessageBox.Show(sb.ToString());
                        }
                        else
                        {
                            MessageBox.Show("No selected features");
                        }
                    }
                });
            });
        }
Beispiel #2
0
        public MgCurveString CreateCurveString(double offset)
        {
            // Create and return a curvestring consisting of
            // one circulararc segment and one linearstring segment

            // arcseg  = (0,0), (0,1), (1,2)
            // lineseg = (1,2), (3,0), (3,2)

            // ArcSegment
            MgCoordinate startPos = factory.CreateCoordinateXY(offset + 0.0, offset + 0.0);
            MgCoordinate midPos   = factory.CreateCoordinateXY(offset + 0.0, offset + 1.0);
            MgCoordinate endPos   = factory.CreateCoordinateXY(offset + 1.0, offset + 2.0);
            MgArcSegment arcSeg   = factory.CreateArcSegment(startPos, endPos, midPos);

            // Linear Segment
            MgCoordinateCollection points = new MgCoordinateCollection();
            MgCoordinate           pt1    = factory.CreateCoordinateXY(offset + 1.0, offset + 2.0);
            MgCoordinate           pt2    = factory.CreateCoordinateXY(offset + 3.0, offset + 0.0);
            MgCoordinate           pt3    = factory.CreateCoordinateXY(offset + 3.0, offset + 2.0);

            points.Add(pt1);
            points.Add(pt2);
            points.Add(pt3);
            MgLinearSegment lineSeg = factory.CreateLinearSegment(points);

            // CurveSegment
            MgCurveSegmentCollection curveSegs = new MgCurveSegmentCollection();

            curveSegs.Add(arcSeg);
            curveSegs.Add(lineSeg);

            return(factory.CreateCurveString(curveSegs));
        }
Beispiel #3
0
        public MgMultiLineString CreateMultiLineString()
        {
            MgCoordinate coord1 = factory.CreateCoordinateXYZ(0.0, 1.0, 2.0);
            MgCoordinate coord2 = factory.CreateCoordinateXYZ(3.0, 4.0, 5.0);
            MgCoordinate coord3 = factory.CreateCoordinateXYZ(6.0, 7.0, 8.0);

            MgCoordinateCollection coordColA = new MgCoordinateCollection();

            coordColA.Add(coord1);
            coordColA.Add(coord2);
            coordColA.Add(coord3);

            MgCoordinate coord4 = factory.CreateCoordinateXYZ(9.0, 10.0, 11.0);
            MgCoordinate coord5 = factory.CreateCoordinateXYZ(12.0, 13.0, 14.0);
            MgCoordinate coord6 = factory.CreateCoordinateXYZ(15.0, 16.0, 17.0);

            MgCoordinateCollection coordColB = new MgCoordinateCollection();

            coordColB.Add(coord4);
            coordColB.Add(coord5);
            coordColB.Add(coord6);

            MgLineString lineString1 = factory.CreateLineString(coordColA);
            MgLineString lineString2 = factory.CreateLineString(coordColB);

            MgLineStringCollection lineStrings = new MgLineStringCollection();

            lineStrings.Add(lineString1);
            lineStrings.Add(lineString2);

            return(factory.CreateMultiLineString(lineStrings));
        }
Beispiel #4
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory      gf          = new MgGeometryFactory();
            MgCoordinate           pt1         = gf.CreateCoordinateXY(0, 0);
            MgCoordinate           pt2         = gf.CreateCoordinateXY(0, 10);
            MgCoordinate           pt3         = gf.CreateCoordinateXY(10, 10);
            MgCoordinate           pt4         = gf.CreateCoordinateXY(10, 0);
            MgCoordinateCollection coordinates = new MgCoordinateCollection();

            coordinates.Add(pt1);
            coordinates.Add(pt2);
            coordinates.Add(pt3);
            coordinates.Add(pt4);
            MgLinearSegment          linearSegment = gf.CreateLinearSegment(coordinates);
            MgCurveSegmentCollection curveSegments = new MgCurveSegmentCollection();

            curveSegments.Add(linearSegment);
            MgCurveString           curveString = gf.CreateCurveString(curveSegments);
            MgCurveStringCollection csc         = new MgCurveStringCollection();

            csc.Add(curveString);
            MgMultiCurveString mcs = gf.CreateMultiCurveString(csc);

            Assert.AreEqual(1, mcs.Count);
            Assert.AreEqual(MgGeometryType.MultiCurveString, mcs.GeometryType);
            Assert.AreEqual(1, mcs.Dimension);
        }
Beispiel #5
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory      gf          = new MgGeometryFactory();
            MgCoordinate           pt1         = gf.CreateCoordinateXY(0, 0);
            MgCoordinate           pt2         = gf.CreateCoordinateXY(0, 10);
            MgCoordinate           pt3         = gf.CreateCoordinateXY(10, 10);
            MgCoordinate           pt4         = gf.CreateCoordinateXY(10, 0);
            MgCoordinateCollection coordinates = new MgCoordinateCollection();

            coordinates.Add(pt1);
            coordinates.Add(pt2);
            coordinates.Add(pt3);
            coordinates.Add(pt4);
            MgLinearSegment          linearSegment = gf.CreateLinearSegment(coordinates);
            MgCurveSegmentCollection curveSegments = new MgCurveSegmentCollection();

            curveSegments.Add(linearSegment);
            MgCurveRing    outerRing = gf.CreateCurveRing(curveSegments);
            MgCurvePolygon cp        = gf.CreateCurvePolygon(outerRing, null);

            Assert.AreEqual(outerRing.ToString(), cp.ExteriorRing.ToString());
            Assert.AreEqual(0, cp.InteriorRingCount);
            Assert.AreEqual(MgGeometryType.CurvePolygon, cp.GeometryType);
            Assert.AreEqual(2, cp.Dimension);
        }
Beispiel #6
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory      gf          = new MgGeometryFactory();
            MgCoordinate           pt1         = gf.CreateCoordinateXY(0, 0);
            MgCoordinate           pt2         = gf.CreateCoordinateXY(0, 10);
            MgCoordinate           pt3         = gf.CreateCoordinateXY(10, 10);
            MgCoordinate           pt4         = gf.CreateCoordinateXY(10, 0);
            MgCoordinateCollection coordinates = new MgCoordinateCollection();

            coordinates.Add(pt1);
            coordinates.Add(pt2);
            coordinates.Add(pt3);
            coordinates.Add(pt4);
            MgLinearSegment          linearSegment = gf.CreateLinearSegment(coordinates);
            MgCurveSegmentCollection curveSegments = new MgCurveSegmentCollection();

            curveSegments.Add(linearSegment);
            MgCurveString curveString = gf.CreateCurveString(curveSegments);

            Assert.AreEqual(1, curveString.Count);
            Assert.AreEqual(pt1.ToString(), curveString.StartCoordinate.ToString());
            Assert.AreEqual(pt4.ToString(), curveString.EndCoordinate.ToString());
            Assert.AreEqual(MgGeometryType.CurveString, curveString.GeometryType);
            Assert.AreEqual(1, curveString.Dimension);
        }
Beispiel #7
0
        private MgByteReader Plot(MapGuideViewerInputModel input, bool useLayout, double?scale)
        {
            MgSiteConnection conn = CreateConnection(input);
            MgMap            map  = new MgMap(conn);

            map.Open(input.MapName);

            MgPoint      center = map.ViewCenter;
            MgCoordinate coord  = center.Coordinate;

            MgMappingService mappingService = (MgMappingService)conn.CreateService(MgServiceType.MappingService);

            MgDwfVersion        dwfVersion = new MgDwfVersion("6.01", "1.2");
            MgPlotSpecification plotSpec   = new MgPlotSpecification(8.5f, 11f, MgPageUnitsType.Inches, 0f, 0f, 0f, 0f);

            plotSpec.SetMargins(0.5f, 0.5f, 0.5f, 0.5f);

            MgLayout layout = null;

            if (useLayout)
            {
                MgResourceIdentifier layoutRes = new MgResourceIdentifier("Library://Samples/Sheboygan/Layouts/SheboyganMap.PrintLayout");
                layout = new MgLayout(layoutRes, "City of Sheboygan", MgPageUnitsType.Inches);
            }

            if (!scale.HasValue)
            {
                return(mappingService.GeneratePlot(map, plotSpec, layout, dwfVersion));
            }
            else
            {
                MgCoordinate mapCenter = map.GetViewCenter().GetCoordinate();
                return(mappingService.GeneratePlot(map, mapCenter, scale.Value, plotSpec, layout, dwfVersion));
            }
        }
Beispiel #8
0
        public MgCurveRing CreateCurveRing(double offset)
        {
            // Ring is a closed entity.
            // Create and return a ring consisting of
            // one circulararc segment and one linearstring segment

            // arcseg  = (0,0), (0,1), (1,2)
            // lineseg = (1,2), (0,0)



            // ArcSegment
            MgCoordinate startPos = factory.CreateCoordinateXY(offset + 0.0, offset + 0.0);
            MgCoordinate midPos   = factory.CreateCoordinateXY(offset + 0.0, offset + 1.0);
            MgCoordinate endPos   = factory.CreateCoordinateXY(offset + 1.0, offset + 2.0);
            MgArcSegment arcSeg   = factory.CreateArcSegment(startPos, endPos, midPos);

            // Linear Segment
            MgCoordinateCollection points = new MgCoordinateCollection();
            MgCoordinate           fromPt = factory.CreateCoordinateXY(offset + 1.0, offset + 2.0);
            MgCoordinate           toPt   = factory.CreateCoordinateXY(offset + 0.0, offset + 0.0);

            points.Add(fromPt);
            points.Add(toPt);
            MgLinearSegment lineSeg = factory.CreateLinearSegment(points);

            // Curve Segment
            MgCurveSegmentCollection curveSegs = new MgCurveSegmentCollection();

            curveSegs.Add(arcSeg);
            curveSegs.Add(lineSeg);

            return(factory.CreateCurveRing(curveSegs));
        }
Beispiel #9
0
        /// <summary>
        /// Coordinate transformation between two world coordinate systems
        /// This Version works with coordinates as X, Y doubles
        /// </summary>
        /// <param name="wkTextSource">The wk text source.</param>
        /// <param name="wkTextTarget">The wk text target.</param>
        /// <param name="inputPointX">The input point X.</param>
        /// <param name="inputPointY">The input point Y.</param>
        /// <param name="transformedPointX">The transformed point X.</param>
        /// <param name="transformedPointY">The transformed point Y.</param>
        /// <returns></returns>
        public static bool TransformPoint2d(string wkTextSource, string wkTextTarget, double inputPointX, double inputPointY, ref double transformedPointX, ref double transformedPointY)
        {
            bool RetVal = false;

            //_logger.Debug("Start TransformPoint2d");
            try
            {
                //Creating coordinate system factory
                MgCoordinateSystemFactory CSFactory = new MgCoordinateSystemFactory();
                //Creating coordinate system objects
                MgCoordinateSystem SourceCS = CSFactory.Create(wkTextSource);
                MgCoordinateSystem TargetCS = CSFactory.Create(wkTextTarget);
                //Creating geometry factory
                MgGeometryFactory GeomFactory = new MgGeometryFactory();
                //Populating geometry factory CreateCoordinateXY
                MgCoordinate SourceCoord = GeomFactory.CreateCoordinateXY(inputPointX, inputPointY);
                //Getting transformation definition
                MgCoordinateSystemTransform CSTransform = CSFactory.GetTransform(SourceCS, TargetCS);
                //Transforming coordinate
                MgCoordinate TargetCoord = CSTransform.Transform(SourceCoord);
                //Populating return coordinate objects
                transformedPointX = TargetCoord.X;
                transformedPointY = TargetCoord.Y;
                RetVal            = true;
            }
            catch (System.Exception ex)
            {
                //_logger.Error("Error in TransformPoint2d", ex);
                throw;
            }
            //_logger.Debug("End TransformPoint2d");
            return(RetVal);
        }
Beispiel #10
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory      gf          = new MgGeometryFactory();
            MgCoordinate           pt1         = gf.CreateCoordinateXY(0, 0);
            MgCoordinate           pt2         = gf.CreateCoordinateXY(0, 10);
            MgCoordinate           pt3         = gf.CreateCoordinateXY(10, 10);
            MgCoordinate           pt4         = gf.CreateCoordinateXY(10, 0);
            MgCoordinateCollection coordinates = new MgCoordinateCollection();

            coordinates.Add(pt1);
            coordinates.Add(pt2);
            coordinates.Add(pt3);
            coordinates.Add(pt4);
            MgLinearSegment          linearSegment = gf.CreateLinearSegment(coordinates);
            MgCurveSegmentCollection curveSegments = new MgCurveSegmentCollection();
            MgCurveRing              curveRing     = gf.CreateCurveRing(curveSegments);
            MgCurvePolygon           cp            = gf.CreateCurvePolygon(curveRing, null);
            MgCurvePolygonCollection cpc           = new MgCurvePolygonCollection();

            cpc.Add(cp);
            MgMultiCurvePolygon mcp = gf.CreateMultiCurvePolygon(cpc);

            Assert.AreEqual(1, mcp.Count);
            Assert.AreEqual(MgGeometryType.MultiCurvePolygon, mcp.GeometryType);
            Assert.AreEqual(2, mcp.Dimension);
        }
Beispiel #11
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory gf = new MgGeometryFactory();
            MgCoordinate      c1 = gf.CreateCoordinateXY(1.0, 1.0);
            MgCoordinate      c2 = gf.CreateCoordinateXY(2.0, 2.0);
            MgCoordinate      c3 = gf.CreateCoordinateXY(3.0, 3.0);
            MgCoordinate      c4 = gf.CreateCoordinateXY(4.0, 4.0);

            MgCoordinateCollection coll = new MgCoordinateCollection();

            coll.Add(c1);
            coll.Insert(1, c2);
            coll.Add(c3);
            coll.Add(c4);

            Assert.AreEqual(4, coll.Count);
            Assert.AreEqual(1.0, coll[0].GetX());
            coll[3] = coll[2];
            Assert.AreEqual(3.0, coll[3].GetX());

            double sum = 0.0;

            foreach (MgCoordinate coord in coll)
            {
                sum += coord.GetX();
            }
            Assert.AreEqual(9.0, sum);
        }
Beispiel #12
0
        public MgArcSegment CreateArcSegment(double offset)
        {
            MgCoordinate startPos = factory.CreateCoordinateXY(offset + 0.0, offset + 0.0);
            MgCoordinate midPos   = factory.CreateCoordinateXY(offset + 0.0, offset + 1.0);
            MgCoordinate endPos   = factory.CreateCoordinateXY(offset + 1.0, offset + 2.0);

            return(factory.CreateArcSegment(startPos, endPos, midPos));
        }
Beispiel #13
0
    string pointTransformAndWriteZ(string geom, MgMap map)
    {
        double[] x = new double[1];
        double[] y = new double[1];
        double[] z = new double[1];

        MgWktReaderWriter wktrwdmr = new MgWktReaderWriter();
        MgPoint           cntr     = wktrwdmr.Read(geom).Centroid;

        x[0] = cntr.Coordinate.X;
        y[0] = cntr.Coordinate.Y;
        z[0] = 0;

        StringBuilder output = new StringBuilder();

        output.Append("<table width=\"100%\" class=\"results\">");

        //WGS preko MG API
        MgCoordinateSystemFactory fact = new MgCoordinateSystemFactory();
        string wktFrom = map.GetMapSRS();

        string wktTo = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]";

        MgCoordinateSystem          CSSource       = fact.Create(wktFrom);
        MgCoordinateSystem          CSTarget       = fact.Create(wktTo);
        MgCoordinateSystemTransform coordTransform = fact.GetTransform(CSSource, CSTarget);

        MgGeometryFactory geomFact = new MgGeometryFactory();

        // GK
        //samo prvo višino zaenkrat, dokler ni enačbe za Z
        output.Append(String.Format("<tr><td class='header'><b>Map koordinates:</b></td><td class=\"results\"><table><tr><td><b>Y:</b></td><td>{0}</td></tr><tr><td><b>X:</b></td><td>{1}</td></tr></table></td></tr>", string.Format("{0:0.0}", x[0]), string.Format("{0:0.0}", y[0])));

        int i = 0;

        //transformacija preko MG koordinatnega sistema
        foreach (double pointX in x)
        {
            MgCoordinate coord = geomFact.CreateCoordinateXY(x[i], y[i]);
            coord = coordTransform.Transform(coord);

            x[i] = coord.X;
            y[i] = coord.Y;

            i++;
        }

        double[] xwgs = x;
        double[] ywgs = y;
        output.Append(String.Format("<tr><td class='header'><b>WGS84:</b></td><td class=\"results\"><table><tr><td><b>Lon:</b></td><td>{0}</td></tr><tr><td><b>Lat:</b></td><td>{1}</td></tr></table></td></tr>", string.Format("{0:0.000000}", xwgs[0]), string.Format("{0:0.000000}", ywgs[0])));

        output.Append("</table>");

        return(output.ToString());
    }
Beispiel #14
0
        public MgPolygon CreatePolygon(double offset)
        {
            // OuterRing
            MgCoordinate oCoord1 = factory.CreateCoordinateXY(offset + 0.0, 0.0);
            MgCoordinate oCoord2 = factory.CreateCoordinateXY(offset + 5.0, 0.0);
            MgCoordinate oCoord3 = factory.CreateCoordinateXY(offset + 5.0, 5.0);
            MgCoordinate oCoord4 = factory.CreateCoordinateXY(offset + 0.0, 5.0);
            MgCoordinate oCoord5 = factory.CreateCoordinateXY(offset + 0.0, 0.0);

            MgCoordinateCollection outerRingCoord = new MgCoordinateCollection();

            outerRingCoord.Add(oCoord1);
            outerRingCoord.Add(oCoord2);
            outerRingCoord.Add(oCoord3);
            outerRingCoord.Add(oCoord4);
            outerRingCoord.Add(oCoord5);

            // Inner Ring1
            MgCoordinate i1Coord1 = factory.CreateCoordinateXY(offset + 1.0, 1.0);
            MgCoordinate i1Coord2 = factory.CreateCoordinateXY(offset + 2.0, 1.0);
            MgCoordinate i1Coord3 = factory.CreateCoordinateXY(offset + 2.0, 2.0);
            MgCoordinate i1Coord4 = factory.CreateCoordinateXY(offset + 1.0, 1.0);

            MgCoordinateCollection inner1RingCoord = new MgCoordinateCollection();

            inner1RingCoord.Add(i1Coord1);
            inner1RingCoord.Add(i1Coord2);
            inner1RingCoord.Add(i1Coord3);
            inner1RingCoord.Add(i1Coord4);

            // Inner Ring2
            MgCoordinate i2Coord1 = factory.CreateCoordinateXY(offset + 3.0, 3.0);
            MgCoordinate i2Coord2 = factory.CreateCoordinateXY(offset + 4.0, 3.0);
            MgCoordinate i2Coord3 = factory.CreateCoordinateXY(offset + 4.0, 4.0);
            MgCoordinate i2Coord4 = factory.CreateCoordinateXY(offset + 3.0, 3.0);

            MgCoordinateCollection inner2RingCoord = new MgCoordinateCollection();

            inner2RingCoord.Add(i2Coord1);
            inner2RingCoord.Add(i2Coord2);
            inner2RingCoord.Add(i2Coord3);
            inner2RingCoord.Add(i2Coord4);

            MgLinearRing extRing  = factory.CreateLinearRing(outerRingCoord);
            MgLinearRing intRing1 = factory.CreateLinearRing(inner1RingCoord);
            MgLinearRing intRing2 = factory.CreateLinearRing(inner2RingCoord);

            MgLinearRingCollection intRings = new MgLinearRingCollection();

            intRings.Add(intRing1);
            intRings.Add(intRing2);

            return(factory.CreatePolygon(extRing, intRings));
        }
Beispiel #15
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory gf    = new MgGeometryFactory();
            MgCoordinateXY    coord = gf.CreateCoordinateXY(100, 100) as MgCoordinateXY;

            Assert.AreEqual(100, coord.X);
            Assert.AreEqual(100, coord.Y);
            MgCoordinate coord2 = coord;

            Assert.AreEqual(100, coord2.X);
            Assert.AreEqual(100, coord2.Y);
        }
Beispiel #16
0
        private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            MgMapViewerProvider provider  = _viewer.GetProvider();
            MgSelectionBase     selection = _viewer.GetSelection();
            MgMapBase           map       = _viewer.GetMap();
            MgPoint             pt        = map.ViewCenter;
            MgCoordinate        coord     = pt.Coordinate;
            float leftMargin = e.MarginBounds.Left;
            float topMargin  = e.MarginBounds.Top;
            float yPos       = topMargin;
            float pageHeight = e.MarginBounds.Height;

            //Write title
            var titleFont = new Font(FontFamily.GenericSansSerif, 18.0f, GraphicsUnit.Point);
            var sizeTitle = e.Graphics.MeasureString(txtTitle.Text, titleFont);

            e.Graphics.DrawString(txtTitle.Text, titleFont, Brushes.Black, new PointF(leftMargin, yPos));

            yPos += (sizeTitle.Height * 1.1f);

            var scaleFont = SystemFonts.CaptionFont;
            var scaleStr  = string.Format("{0} 1 : {1}", Strings.TextScale, _viewer.GetMap().ViewScale); //NOXLATE
            var sizeScale = e.Graphics.MeasureString(scaleStr, scaleFont);

            //Scale to fit within this page
            var imgHeight = (int)(pageHeight - (sizeTitle.Height * 1.1f) - (sizeScale.Height * 1.1f));
            var imgWidth  = e.MarginBounds.Width;

            using (var state = provider.CreateTransientState())
            {
                var tempState = new MgMapDisplayParameters(coord.X, coord.Y, map.ViewScale, imgWidth, imgHeight, (int)numDPI.Value);
                state.PushState(tempState);
                MgByteReader br = provider.RenderMap(selection, "PNG"); //NOXLATE
                using (MgReadOnlyStream stream = new MgReadOnlyStream(br))
                {
                    Image img = Image.FromStream(stream);
                    e.Graphics.DrawImage(img, leftMargin, yPos, imgWidth, imgHeight);
                    img.Dispose();
                }
            }

            yPos += imgHeight;

            //Render scale
            if (chkScale.Checked)
            {
                e.Graphics.DrawString(scaleStr, scaleFont, Brushes.Black, new PointF(leftMargin, yPos));
            }

            e.HasMorePages = false;
        }
Beispiel #17
0
 private void AddPoint(RedlineTextFunction retrieveTextMethod, RedlineAction onRedlineAdded)
 {
     _viewer.DigitizePoint((x, y) =>
     {
         string text = string.Empty;
         if (retrieveTextMethod != null)
         {
             text = retrieveTextMethod();
         }
         MgCoordinate coord = _geomFact.CreateCoordinateXY(x, y);
         MgGeometry point   = _geomFact.CreatePoint(coord);
         InsertRedlineGeometry(text, point, onRedlineAdded);
     });
 }
Beispiel #18
0
        public MgLineString CreateLineString(double offset)
        {
            MgCoordinateCollection coordCol = new MgCoordinateCollection();

            MgCoordinate coord1 = factory.CreateCoordinateXY(offset + 0.0, 1.0);
            MgCoordinate coord2 = factory.CreateCoordinateXY(offset + 2.0, 3.0);
            MgCoordinate coord3 = factory.CreateCoordinateXY(offset + 4.0, 5.0);

            coordCol.Add(coord1);
            coordCol.Add(coord2);
            coordCol.Add(coord3);

            return(factory.CreateLineString(coordCol));
        }
Beispiel #19
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory      gf          = new MgGeometryFactory();
            MgCoordinate           pt1         = gf.CreateCoordinateXY(0, 0);
            MgCoordinate           pt2         = gf.CreateCoordinateXY(0, 10);
            MgCoordinate           pt3         = gf.CreateCoordinateXY(10, 10);
            MgCoordinate           pt4         = gf.CreateCoordinateXY(10, 0);
            MgCoordinateCollection coordinates = new MgCoordinateCollection();

            coordinates.Add(pt1);
            coordinates.Add(pt2);
            coordinates.Add(pt3);
            coordinates.Add(pt4);
            MgLinearRing linearRing = gf.CreateLinearRing(coordinates);

            Assert.AreEqual(MgGeometryComponentType.LinearRing, linearRing.ComponentType);
            Assert.AreEqual(2, linearRing.Dimension);
        }
Beispiel #20
0
        public MgLinearRing CreateLinearRing(double offset)
        {
            MgCoordinate oCoord1 = factory.CreateCoordinateXY(0.0, offset);
            MgCoordinate oCoord2 = factory.CreateCoordinateXY(5.0, offset);
            MgCoordinate oCoord3 = factory.CreateCoordinateXY(5.0, offset + 5.0);
            MgCoordinate oCoord4 = factory.CreateCoordinateXY(0.0, offset + 5.0);
            MgCoordinate oCoord5 = factory.CreateCoordinateXY(0.0, offset);

            MgCoordinateCollection outerRingCoord = new MgCoordinateCollection();

            outerRingCoord.Add(oCoord1);
            outerRingCoord.Add(oCoord2);
            outerRingCoord.Add(oCoord3);
            outerRingCoord.Add(oCoord4);
            outerRingCoord.Add(oCoord5);

            return(factory.CreateLinearRing(outerRingCoord));
        }
Beispiel #21
0
        public MgMultiPoint CreateMultiPoint()
        {
            MgCoordinate coord1 = factory.CreateCoordinateXYZ(1.0, 2.0, 3.0);
            MgPoint      point1 = factory.CreatePoint(coord1);

            MgCoordinate coord2 = factory.CreateCoordinateXYZ(4.0, 5.0, 6.0);
            MgPoint      point2 = factory.CreatePoint(coord2);

            MgCoordinate coord3 = factory.CreateCoordinateXYZ(7.0, 8.0, 9.0);
            MgPoint      point3 = factory.CreatePoint(coord3);

            MgPointCollection pnts = new MgPointCollection();

            pnts.Add(point1);
            pnts.Add(point2);
            pnts.Add(point3);

            return(factory.CreateMultiPoint(pnts));
        }
Beispiel #22
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory      gf          = new MgGeometryFactory();
            MgCoordinate           pt1         = gf.CreateCoordinateXY(0, 0);
            MgCoordinate           pt2         = gf.CreateCoordinateXY(0, 10);
            MgCoordinate           pt3         = gf.CreateCoordinateXY(10, 10);
            MgCoordinate           pt4         = gf.CreateCoordinateXY(10, 0);
            MgCoordinateCollection coordinates = new MgCoordinateCollection();

            coordinates.Add(pt1);
            coordinates.Add(pt2);
            coordinates.Add(pt3);
            coordinates.Add(pt4);
            MgLinearSegment linearSegment = gf.CreateLinearSegment(coordinates);

            Assert.AreEqual(MgGeometryComponentType.LinearSegment, linearSegment.ComponentType);
            Assert.AreEqual(pt1.ToString(), linearSegment.StartCoordinate.ToString());
            Assert.AreEqual(pt4.ToString(), linearSegment.EndCoordinate.ToString());
            Assert.AreEqual(1, linearSegment.Dimension);
        }
Beispiel #23
0
        // GET: DwfPlot
        public ActionResult Index(MapGuideViewerInputModel input)
        {
            MgSiteConnection conn = CreateConnection(input);
            MgMap            map  = new MgMap(conn);

            map.Open(input.MapName);

            MgPoint      center = map.ViewCenter;
            MgCoordinate coord  = center.Coordinate;

            DwfPlotViewModel vm = new DwfPlotViewModel()
            {
                MapName = input.MapName,
                Session = input.Session,
                Scale   = map.GetViewScale(),
                X       = coord.X,
                Y       = coord.Y
            };

            return(View(vm));
        }
Beispiel #24
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory      gf          = new MgGeometryFactory();
            MgCoordinate           pt1         = gf.CreateCoordinateXY(0, 0);
            MgCoordinate           pt2         = gf.CreateCoordinateXY(0, 10);
            MgCoordinate           pt3         = gf.CreateCoordinateXY(10, 10);
            MgCoordinate           pt4         = gf.CreateCoordinateXY(10, 0);
            MgCoordinateCollection coordinates = new MgCoordinateCollection();

            coordinates.Add(pt1);
            coordinates.Add(pt2);
            coordinates.Add(pt3);
            coordinates.Add(pt4);
            MgLinearRing linearRing = gf.CreateLinearRing(coordinates);
            MgPolygon    polygon    = gf.CreatePolygon(linearRing, null);

            Assert.AreEqual(linearRing.ToString(), polygon.ExteriorRing.ToString());
            Assert.AreEqual(0, polygon.InteriorRingCount);
            Assert.AreEqual(MgGeometryType.Polygon, polygon.GeometryType);
            Assert.AreEqual(2, polygon.Dimension);
        }
Beispiel #25
0
        private void btnRenderMap2_Click(object sender, EventArgs e)
        {
            //Note we're casting to mg-desktop specific subclasses as this is what mg-desktop rendering APIs expect
            MgdMap              map         = (MgdMap)_viewer.GetMap();
            MgdSelection        selection   = (MgdSelection)_viewer.GetSelection();
            MgMapViewerProvider provider    = _viewer.GetProvider();
            MgdRenderingService renderSvc   = (MgdRenderingService)provider.CreateService(MgServiceType.RenderingService);
            MgPoint             centerPt    = map.ViewCenter;
            MgCoordinate        centerCoord = centerPt.Coordinate;

            //MgdTransientMapState is a helper class which lets us apply transient state to a map, which is automatically
            //undone on disposal. This is how we can render custom views of a map with specific display parameters without
            //permanently changing the display parameters used by the map viewer
            using (MgTransientMapState tempState = provider.CreateTransientState(map))
            {
                MgMapDisplayParameters state = new MgMapDisplayParameters(centerCoord.X, centerCoord.Y, 5000, 1024, 768, 96);
                tempState.PushState(state);

                MgByteReader br = renderSvc.RenderMap(map, selection, "PNG");
                using (SaveFileDialog save = new SaveFileDialog())
                {
                    save.Filter = "Portable Network Graphics (*.png)|*.png";
                    if (save.ShowDialog() == DialogResult.OK)
                    {
                        //MgReadOnlyStream is a stream adapter class that provides a .net stream
                        //interface to the MgByteReader, allowing MgByteReader objects to be used
                        //anywhere a System.IO.Stream is expected.
                        using (MgReadOnlyStream stream = new MgReadOnlyStream(br))
                        {
                            Image img = Image.FromStream(stream);
                            img.Save(save.FileName);
                            MessageBox.Show("Image saved to: " + save.FileName);
                        }
                    }
                    br.Dispose();
                }
            }
        }
Beispiel #26
0
    public static string TransformGK2Wgs(double x, double y, string ss, string mpN) //Transform from Map to WGS 84 Coordtnate System
    {
        MgMap             map          = new MgMap();
        MgResourceService resourceSrvc = GetMgResurceService(ss);

        map.Open(resourceSrvc, mpN);

        //Create coordinate system factory
        MgCoordinateSystemFactory fact = new MgCoordinateSystemFactory();
        string wktFrom = map.GetMapSRS();
        string wktTo   = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]";

        MgCoordinateSystem coordinateSystemSource = fact.Create(wktFrom);
        MgCoordinateSystem coordinateSystemTarget = fact.Create(wktTo);

        MgGeometryFactory geomFact = new MgGeometryFactory();

        MgCoordinateSystemTransform coordTransform = fact.GetTransform(coordinateSystemSource, coordinateSystemTarget);

        MgCoordinate coord = coordTransform.Transform(x, y);

        return(coord.X.ToString().Replace(',', '.') + ";" + coord.Y.ToString().Replace(',', '.'));
    }
Beispiel #27
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory      gf          = new MgGeometryFactory();
            MgCoordinate           pt1         = gf.CreateCoordinateXY(0, 0);
            MgCoordinate           pt2         = gf.CreateCoordinateXY(0, 10);
            MgCoordinate           pt3         = gf.CreateCoordinateXY(10, 10);
            MgCoordinate           pt4         = gf.CreateCoordinateXY(10, 0);
            MgCoordinateCollection coordinates = new MgCoordinateCollection();

            coordinates.Add(pt1);
            coordinates.Add(pt2);
            coordinates.Add(pt3);
            coordinates.Add(pt4);
            MgLineString           ls = gf.CreateLineString(coordinates);
            MgLineStringCollection lineStringCollection = new MgLineStringCollection();

            lineStringCollection.Add(ls);
            MgMultiLineString mls = gf.CreateMultiLineString(lineStringCollection);

            Assert.AreEqual(1, mls.Count);
            Assert.AreEqual(MgGeometryType.MultiLineString, mls.GeometryType);
            Assert.AreEqual(1, mls.Dimension);
        }
Beispiel #28
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory      gf          = new MgGeometryFactory();
            MgCoordinate           pt1         = gf.CreateCoordinateXY(0, 0);
            MgCoordinate           pt2         = gf.CreateCoordinateXY(0, 10);
            MgCoordinate           pt3         = gf.CreateCoordinateXY(10, 10);
            MgCoordinate           pt4         = gf.CreateCoordinateXY(10, 0);
            MgCoordinateCollection coordinates = new MgCoordinateCollection();

            coordinates.Add(pt1);
            coordinates.Add(pt2);
            coordinates.Add(pt3);
            coordinates.Add(pt4);
            MgLinearSegment          linearSegment = gf.CreateLinearSegment(coordinates);
            MgCurveSegmentCollection curveSegments = new MgCurveSegmentCollection();

            curveSegments.Add(linearSegment);
            MgCurveRing outerRing = gf.CreateCurveRing(curveSegments);

            Assert.AreEqual(MgGeometryComponentType.CurveRing, outerRing.ComponentType);
            Assert.AreEqual(1, outerRing.Count);
            Assert.AreEqual(2, outerRing.Dimension);
        }
Beispiel #29
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgGeometryFactory gf     = new MgGeometryFactory();
            MgCoordinate      pt1    = gf.CreateCoordinateXY(0, 0);
            MgCoordinate      pt2    = gf.CreateCoordinateXY(0, 10);
            MgCoordinate      pt3    = gf.CreateCoordinateXY(10, 10);
            MgCoordinate      pt4    = gf.CreateCoordinateXY(10, 0);
            MgPoint           mgpt1  = gf.CreatePoint(pt1);
            MgPoint           mgpt2  = gf.CreatePoint(pt2);
            MgPoint           mgpt3  = gf.CreatePoint(pt3);
            MgPoint           mgpt4  = gf.CreatePoint(pt4);
            MgPointCollection points = new MgPointCollection();

            points.Add(mgpt1);
            points.Add(mgpt2);
            points.Add(mgpt3);
            points.Add(mgpt4);
            MgMultiPoint mp = gf.CreateMultiPoint(points);

            Assert.AreEqual(4, mp.Count);
            Assert.AreEqual(MgGeometryType.MultiPoint, mp.GeometryType);
            Assert.AreEqual(0, mp.Dimension);
        }
Beispiel #30
0
        public void LoadResults(MgLayerBase layer, MgFeatureQueryOptions query)
        {
            MgClassDefinition clsDef = layer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = clsDef.GetIdentityProperties();
            MgPropertyDefinition           idProp  = idProps[0];
            string idPropName = idProp.Name;
            string geomName   = layer.FeatureGeometryName;

            MgFeatureReader   reader = layer.SelectFeatures(query);
            MgAgfReaderWriter agfRw  = new MgAgfReaderWriter();

            try
            {
                while (reader.ReadNext())
                {
                    var res = new ParcelFeatureModel();
                    res.ID      = reader.GetInt32(idPropName);
                    res.Owner   = reader.IsNull("RNAME") ? "(unknown)" : reader.GetString("RNAME");
                    res.Address = reader.IsNull("RPROPAD") ? "(unknown)" : reader.GetString("RPROPAD");
                    if (!reader.IsNull(geomName))
                    {
                        MgByteReader agf    = reader.GetGeometry(geomName);
                        MgGeometry   geom   = agfRw.Read(agf);
                        MgPoint      center = geom.Centroid;
                        MgCoordinate coord  = center.Coordinate;

                        res.X = coord.X;
                        res.Y = coord.Y;
                    }
                    this.Results.Add(res);
                }
            }
            finally
            {
                reader.Close();
            }
        }