Example #1
0
        async public Task <ICursor> PointQuery(gView.Framework.Carto.IDisplay display, IPoint point, ISpatialReference sRef, IUserData userdata)
        {
            PointCollection pColl = new PointCollection();

            pColl.AddPoint(point);

            return(await MultiPointQuery(display, pColl, sRef, userdata));
        }
Example #2
0
        private static string Convert2DMultiPointToJsonString(IMultiPoint multiPoint, int spatialReferenceId, bool hasZ, bool hasM)
        {
            PointCollection pointCollection;
            int             pathCount = multiPoint.PointCount;

            PointCollection[] pointCollectionArray = new PointCollection[pathCount];
            for (int pathIndex = 0; pathIndex < pathCount; pathIndex++)
            {
                IPoint point = multiPoint[pathIndex];
                //int pointCount = point.PointCount;

                pointCollection = new PointCollection();

                pointCollection.AddPoint(new Point(point.X, point.Y));

                pointCollectionArray[pathIndex] = pointCollection;
            }

            return(Convert2DPointCollectionToJsonString(pointCollectionArray, PointCollectionParent.points, spatialReferenceId, hasZ, hasM));
        }
Example #3
0
        private void ReadPoints(int numPoints, PointCollection pointCol)
        {
            unsafe
            {
                fixed(void *b = _shp.ReadBytes(sizeof(double) * 2 * numPoints))
                {
                    double *p = (double *)b;

                    for (int i = 0; i < numPoints; i++)
                    {
                        pointCol.AddPoint(new Point(*p++, *p++));
                    }
                }
            }

            /*
             *
             *          for(int i=0;i<numPoints;i++)
             *          {
             *                  pointCol.AddPoint(new Point(_shp.ReadDouble(),_shp.ReadDouble()));
             *          }*/
        }
Example #4
0
        private static string Convert2DPolygonToJsonString(IPolygon polygon, int spatialReferenceId, bool hasZ, bool hasM)
        {
            PointCollection pointCollection;
            int             ringCount = polygon.RingCount;

            PointCollection[] pointCollectionArray = new PointCollection[ringCount];
            for (int ringIndex = 0; ringIndex < ringCount; ringIndex++)
            {
                IRing ring       = polygon[ringIndex];
                int   pointCount = ring.PointCount;

                pointCollection = new PointCollection();

                for (int pointIndex = 0; pointIndex < pointCount; pointIndex++)
                {
                    pointCollection.AddPoint(Clone(ring[pointIndex]));
                }
                pointCollectionArray[ringIndex] = pointCollection;
            }

            return(Convert2DPointCollectionToJsonString(pointCollectionArray, PointCollectionParent.rings, spatialReferenceId, hasZ, hasM));
        }
Example #5
0
        private static string Convert2DPolylineToJsonString(IPolyline polyline, int spatialReferenceId, bool hasZ, bool hasM)
        {
            PointCollection pointCollection;
            int             pathCount = polyline.PathCount;

            PointCollection[] pointCollectionArray = new PointCollection[pathCount];
            for (int pathIndex = 0; pathIndex < pathCount; pathIndex++)
            {
                IPath path       = polyline[pathIndex];
                int   pointCount = path.PointCount;

                pointCollection = new PointCollection();

                for (int pointIndex = 0; pointIndex < pointCount; pointIndex++)
                {
                    pointCollection.AddPoint(Clone(path[pointIndex]));
                }
                pointCollectionArray[pathIndex] = pointCollection;
            }

            return(Convert2DPointCollectionToJsonString(pointCollectionArray, PointCollectionParent.paths, spatialReferenceId, hasZ, hasM));
        }
Example #6
0
        async public Task <float[]> MultiGridQuery(gView.Framework.Carto.IDisplay display, IPoint[] Points, double dx, double dy, ISpatialReference sRef, IUserData userdata)
        {
            if (Points == null || Points.Length != 3)
            {
                return(null);
            }

            PointCollection pColl = new PointCollection();

            pColl.AddPoint(Points[0]);
            pColl.AddPoint(Points[1]);
            pColl.AddPoint(Points[2]);

            double d1x = Points[1].X - Points[0].X, d1y = Points[1].Y - Points[0].Y;
            double d2x = Points[2].X - Points[0].X, d2y = Points[2].Y - Points[0].Y;
            double len1  = Math.Sqrt(d1x * d1x + d1y * d1y);
            double len2  = Math.Sqrt(d2x * d2x + d2y * d2y);
            int    stepX = (int)Math.Round(len1 / dx);
            int    stepY = (int)Math.Round(len2 / dy);

            d1x /= stepX; d1y /= stepX;
            d2x /= stepY; d2y /= stepY;

            List <float> vals = new List <float>();

            vals.Add((float)(stepX + 1));
            vals.Add((float)(stepY + 1));

            List <IRasterLayer> layers = await QueryChildLayers(pColl.Envelope, String.Empty);

            try
            {
                for (int y = 0; y <= stepY; y++)
                {
                    for (int x = 0; x <= stepX; x++)
                    {
                        Point p = new Point(Points[0].X + d1x * x + d2x * y,
                                            Points[0].Y + d1y * x + d2y * y);

                        bool found = false;
                        foreach (IRasterLayer layer in layers)
                        {
                            if (layer == null ||
                                !(layer.Class is IRasterClass) ||
                                !(layer.Class is IGridIdentify))
                            {
                                continue;
                            }

                            if (gView.Framework.SpatialAlgorithms.Algorithm.Jordan(((IRasterClass)layer.Class).Polygon, p.X, p.Y))
                            {
                                ((IGridIdentify)layer.Class).InitGridQuery();
                                float val = ((IGridIdentify)layer.Class).GridQuery(display, p, sRef);
                                vals.Add(val);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            vals.Add(float.MinValue);
                        }
                    }
                }
            }
            finally
            {
                foreach (IRasterLayer layer in layers)
                {
                    if (layer.Class is IGridIdentify)
                    {
                        ((IGridIdentify)layer.Class).ReleaseGridQuery();
                    }
                }
            }


            return(vals.ToArray());
        }
Example #7
0
        static void TestProj4()
        {
            var sRef4326 = SpatialReference.FromID("epsg:4326");

            var sRef31255 = SpatialReference.FromID("epsg:31255");
            var sRef31256 = SpatialReference.FromID("epsg:31256");
            var sRef3857  = SpatialReference.FromID("epsg:3857");
            var sRef23032 = new SpatialReference("test", "", "+proj=utm +zone=32 +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs ", null);

            using (var transformer = GeometricTransformerFactory.Create())
            {
                //var point = new Point(1443413.9574, 6133464.20414);
                ////var point = new Point(-27239.046, 335772.696625);
                //Console.WriteLine(point.X.ToString() + "    " + point.Y.ToString());

                //transformer.SetSpatialReferences(sRef3857, sRef4326);
                //point = (Point)transformer.Transform2D(point);
                //Console.WriteLine(point.X.ToString() + "    " + point.Y.ToString());

                var pCollection = new PointCollection();
                //pCollection.AddPoint(new Point(1443413.9574, 6133464.20414));
                pCollection.AddPoint(new Point(-27239.046, 335772.696625));
                Console.WriteLine(pCollection[0].X.ToString() + "    " + pCollection[0].Y.ToString());

                transformer.SetSpatialReferences(sRef31255, sRef3857);
                pCollection = (PointCollection)transformer.Transform2D(pCollection);
                Console.WriteLine(pCollection[0].X.ToString() + "    " + pCollection[0].Y.ToString());


                //transformer.SetSpatialReferences(sRef3857, sRef4326);
                //point = (Point)transformer.Transform2D(point);
                //Console.WriteLine(point.X.ToString() + "    " + point.Y.ToString());

                //transformer.SetSpatialReferences(sRef4326, sRef31255);
                //point = (Point)transformer.Transform2D(point);
                //Console.WriteLine(point.X.ToString() + "    " + point.Y.ToString());


                //var point = new Point(-27239.046, 335772.696625);

                //Console.WriteLine(point.X.ToString() + "    " + point.Y.ToString());

                //transformer.SetSpatialReferences(sRef31255, sRef23032);
                //var point2 = (Point)transformer.Transform2D(point);

                //Console.WriteLine(point2.X.ToString() + "    " + point2.Y.ToString());

                //transformer.SetSpatialReferences(sRef31255, sRef31256);
                //point2 = (Point)transformer.Transform2D(point);

                //Console.WriteLine(point2.X.ToString() + "    " + point2.Y.ToString());

                //transformer.SetSpatialReferences(sRef31256, sRef3857);
                //point=(Point)transformer.Transform2D(point);

                //Console.WriteLine(point.X.ToString() + "    " + point.Y.ToString());

                //transformer.SetSpatialReferences(sRef4326, sRef3857);
                //point = (Point)transformer.Transform2D(point);

                //Console.WriteLine(point.X.ToString() + "    " + point.Y.ToString());
            }
        }
 public InteriorPath(WorldEditor worldEditor, IWorldContainer parentContainer, string meshName, InteriorPathContents path)
 {
     parent = parentContainer;
     app = worldEditor;
     points = new PointCollection(this, worldEditor, true, worldEditor.Config.DisplayRegionPoints, worldEditor.Config.RegionPointMeshName, worldEditor.Config.RegionPointMaterial);
     nameValuePairs = new NameValueObject();
     points.PointsChanged += new PointsChangedEventHandler(PointsChangedHandler);
     Changed += new InSceneChangedEventHandler(app.SceneChangedHandler);
     foreach (Vector3 position in path.Points)
     {
         int index;
         points.AddPoint(position, out index);
     }
 }
Example #9
0
        public void Draw(IDisplay display, IGeometry geometry)
        {
            try
            {
                IEnvelope dispEnvelope =
                    display.DisplayTransformation != null ?
                    new Envelope(display.DisplayTransformation.TransformedBounds(display)) :
                    new Envelope(display.Envelope);

                //dispEnvelope.Raise(75);
                geometry = SpatialAlgorithms.Clip.PerformClip(dispEnvelope, geometry);
                if (geometry == null)
                {
                    return;
                }

                if (this.LineSymbol != null)
                {
                    //if (this.SymbolSmothingMode != SymbolSmoothing.None)
                    //{
                    //    this.LineSymbol.SymbolSmothingMode = this.SymbolSmothingMode;
                    //}
                    this.LineSymbol.Draw(display, geometry);
                }
                if (this.PointSymbol != null && geometry is IPolyline)
                {
                    //if (this.SymbolSmothingMode != SymbolSmoothing.None)
                    //{
                    //    this.PointSymbol.SymbolSmothingMode = this.SymbolSmothingMode;
                    //}
                    double stepWidthValue = this.StepWidth;
                    double stepStartPosValue = this.StepStartPos;
                    double step = 0, start = 0;
                    double symbolMaxDistance = 0.5 * display.SpatialReference.MetersToDeg(this.SymbolMaxDistance * display.mapScale / (96 / 0.0254));

                    switch (this.StepWidthUnit)
                    {
                    case StepWidthUnit.Pixel:
                        step  = display.SpatialReference.MetersToDeg(stepWidthValue * (display.mapScale / (96 / 0.0254)) /* [m] */);
                        start = display.SpatialReference.MetersToDeg(stepStartPosValue * (display.mapScale / (96 / 0.0254)) /* [m] */);
                        break;
                    }

                    var polyline = ((IPolyline)geometry);

                    foreach (var path in polyline)
                    {
                        if (path == null || path.PointCount == 0)
                        {
                            continue;
                        }

                        var symbolRotation = this.UseSymbolRotation ?
                                             this.PointSymbol as ISymbolRotation :
                                             null;

                        var    length = path.Length;
                        var    pointCount = path.PointCount;
                        double dx, dy;

                        PointCollection pointCollection = new PointCollection();
                        if (pointCount >= 2)
                        {
                            switch (this.StepWidthUnit)
                            {
                            case StepWidthUnit.Percent:
                                step  = length * ((float)stepWidthValue / 100f);
                                start = length * ((float)stepStartPosValue / 100f);
                                break;
                            }

                            #region Step Points

                            if (this.DrawStepPoints && stepWidthValue >= 1 && step > 0.0)
                            {
                                pointCollection = length > step?
                                                  SpatialAlgorithms.Algorithm.PathPoints(path,
                                                                                         fromStat : start > 0.0?start : step,
                                                                                         toStat : length,
                                                                                         step : step,
                                                                                         createPointM2 : true) :
                                                      new PointCollection();
                            }

                            #endregion

                            #region FirstPoint

                            if (this.DrawStartPoint)
                            {
                                dx = path[1].X - path[0].X;
                                dy = path[1].Y - path[0].Y;

                                pointCollection.AddPoint(new PointM2(path[0], 0, Math.Atan2(-dy, dx)));
                            }

                            #endregion

                            #region Last Point

                            if (this.DrawEndPoint)
                            {
                                dx = path[pointCount - 1].X - path[pointCount - 2].X;
                                dy = path[pointCount - 1].Y - path[pointCount - 2].Y;
                                pointCollection.AddPoint(new PointM2(path[path.PointCount - 1], length, Math.Atan2(-dy, dx)));
                            }

                            #endregion
                        }
                        else  // Line with one Vertex!!??  => dont ask => draw!
                        {
                            if (this.DrawStartPoint)
                            {
                                pointCollection = new PointCollection();
                                pointCollection.AddPoint(path[0]);
                            }
                        }

                        var symbolEnvelopes             = symbolMaxDistance > 0 ? new List <IEnvelope>() : null;

                        for (int i = 0, i_to = pointCollection.PointCount; i < i_to; i++)
                        {
                            #region Check Min Dinstance (Intersection)

                            if (symbolMaxDistance > 0)
                            {
                                var symbolEnvelope = new Envelope(-symbolMaxDistance, -symbolMaxDistance, symbolMaxDistance, symbolMaxDistance);
                                symbolEnvelope.TranslateTo(pointCollection[i].X, pointCollection[i].Y);

                                if (symbolEnvelope.IntersectsOne(symbolEnvelopes))
                                {
                                    continue;
                                }

                                symbolEnvelopes.Add(symbolEnvelope);
                            }

                            #endregion

                            if (symbolRotation != null)
                            {
                                if (pointCollection[i] is PointM2)
                                {
                                    float rotation = (float)(Convert.ToSingle(((PointM2)pointCollection[i]).M2) * 180.0 / Math.PI);
                                    symbolRotation.Rotation = rotation;
                                }
                                else
                                {
                                    symbolRotation.Rotation = 0;
                                }
                            }


                            this.PointSymbol.Draw(display, pointCollection[i]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }