Ejemplo n.º 1
0
        private static IGeometry ClipEnvelope(Envelope envelope, IGeometry clippee)
        {
            if (envelope == null || clippee == null)
            {
                return(null);
            }

            if (double.IsInfinity(envelope.Width) ||
                double.IsInfinity(envelope.Height))
            {
                return(clippee);
            }

            IEnvelope geomEnv = clippee.Envelope;

            if (!envelope.Intersects(geomEnv))
            {
                return(null);
            }

            if (geomEnv.minx >= envelope.minx && geomEnv.maxx <= envelope.maxx &&
                geomEnv.miny >= envelope.miny && geomEnv.maxy <= envelope.maxy)
            {
                // Full included...
                return(clippee);
            }

            if (clippee is IMultiPoint)
            {
                // Point ist schon durch den oberen Test enthalten...
                IMultiPoint multipoint    = (IMultiPoint)clippee;
                MultiPoint  newMultiPoint = new MultiPoint();

                for (int i = 0; i < multipoint.PointCount; i++)
                {
                    IPoint point = ClipPoint2Envelope(envelope, multipoint[i]);
                    if (point != null)
                    {
                        newMultiPoint.AddPoint(point);
                    }
                }
                return(newMultiPoint);
            }
            if (clippee is IPolyline)
            {
                return(ClipPolyline2Envelope(envelope, (IPolyline)clippee));
            }
            if (clippee is IPolygon)
            {
                //GeomPolygon clipperGeom = new GeomPolygon(envelope);
                //GeomPolygon clippeeGeom = new GeomPolygon((IPolygon)clippee);

                //GeomPolygon result = clippeeGeom.Clip(ClipOperation.Intersection, clipperGeom);
                //int x = result.NofContours;
                //return result.ToPolygon();
                return(((IPolygon)clippee).Clip(envelope));
            }
            return(null);
        }
Ejemplo n.º 2
0
        static public MultiPoint ToMultiPoint(this GeoJSON.Net.Geometry.MultiPoint geoJsonMultiPoint)
        {
            var multiPoint = new MultiPoint();

            if (geoJsonMultiPoint?.Coordinates != null)
            {
                foreach (var geoJsonPoint in geoJsonMultiPoint.Coordinates)
                {
                    var point = geoJsonPoint.ToPoint();
                    if (point != null)
                    {
                        multiPoint.AddPoint(point);
                    }
                }
            }

            return(multiPoint);
        }
Ejemplo n.º 3
0
        private static MultiPoint CreateMultiPoint(BinaryReader reader, WkbByteOrder byteOrder, bool hasZ, bool hasM)
        {
            // Get the number of points in this multipoint.
            int numPoints = (int)ReadUInt32(reader, byteOrder);

            // Create a new array for the points.
            MultiPoint points = new MultiPoint();

            // Loop on the number of points.
            for (int i = 0; i < numPoints; i++)
            {
                // Read point header
                reader.ReadByte();
                ReadUInt32(reader, byteOrder);

                // Create the next point and add it to the point array.
                points.AddPoint(CreatePoint(reader, byteOrder, hasZ, hasM));
            }
            return(points);
        }
Ejemplo n.º 4
0
        virtual protected IMultiPoint Grabbers(IDisplay display, bool transform)
        {
            MultiPoint coll = new MultiPoint();

            if (display == null || display.GraphicsContainer == null)
            {
                return(coll);
            }

            if (display.GraphicsContainer.EditMode == GrabberMode.Pointer)
            {
                Envelope env = new Envelope(0, 0, 1, 1);

                coll.AddPoint(env.UpperLeft);
                coll.AddPoint(env.UpperRight);
                coll.AddPoint(env.LowerRight);
                coll.AddPoint(env.LowerLeft);

                coll.AddPoint(new Point(env.UpperLeft.X + env.Width / 2, env.UpperLeft.Y));
                coll.AddPoint(new Point(env.UpperRight.X, env.LowerRight.Y + env.Height / 2));
                coll.AddPoint(new Point(env.LowerLeft.X + env.Width / 2, env.LowerLeft.Y));
                coll.AddPoint(new Point(env.LowerLeft.X, env.LowerLeft.Y + env.Width / 2));

                double tol = 25.0 * display.mapScale / (96 / 0.0254);  // [m]
                if (display.SpatialReference != null &&
                    display.SpatialReference.SpatialParameters.IsGeographic)
                {
                    tol = 180.0 * tol / Math.PI / 6370000.0;
                }

                if (_scaleY > 0)
                {
                    coll.AddPoint(new Point(env.UpperLeft.X + env.Width / 2, env.UpperLeft.Y + tol / _scaleY));
                }
                else
                {
                    coll.AddPoint(new Point(env.LowerLeft.X + env.Width / 2, env.LowerLeft.Y + tol / _scaleY));
                }
            }
            else if (display.GraphicsContainer.EditMode == GrabberMode.Vertex &&
                     this is IConstructable && ((IConstructable)this).hasVertices)
            {
                IPointCollection pColl = Vertices(_template.Clone() as IGeometry, -1);
                if (pColl != null)
                {
                    for (int i = 0; i < pColl.PointCount; i++)
                    {
                        coll.AddPoint(pColl[i]);
                    }
                }
            }

            if (transform)
            {
                ScaleGeometry(coll, _scaleX, _scaleY);
                RotateGeometry(coll, Math.Cos(_angle), Math.Sin(_angle));
                TranslateGeometry(coll, _xOffset, _yOffset);
            }

            return(coll);
        }
Ejemplo n.º 5
0
        private IGeometry FetchShape(System.Int16 index)
        {
            unsafe
            {
                System.Int32 err_no    = 0;
                SE_SHAPE     shape_val = new SE_SHAPE();

                System.Int32 *part_offsets = null;
                System.Int32 *subp_offsets = null;
                SE_POINT *    points       = null;
                try
                {
                    err_no = Wrapper10.SE_shape_create(new SE_COORDREF(), ref shape_val);
                    if (err_no != 0)
                    {
                        return(null);
                    }

                    err_no = Wrapper10.SE_stream_get_shape(_stream.SeStream, index, shape_val);
                    if (err_no != 0)
                    {
                        return(null);
                    }

                    Int32 shapeType = 0, numPoints = 0, numParts = 0, numSubparts = 0;

                    err_no = Wrapper10.SE_shape_get_type(shape_val, ref shapeType);
                    if (err_no != 0 || shapeType == CONST.SG_NIL_SHAPE)
                    {
                        return(null);
                    }
                    err_no = Wrapper10.SE_shape_get_num_points(shape_val, 0, 0, ref numPoints);
                    if (err_no != 0)
                    {
                        return(null);
                    }
                    err_no = Wrapper10.SE_shape_get_num_parts(shape_val, ref numParts, ref numSubparts);
                    if (err_no != 0)
                    {
                        return(null);
                    }

                    part_offsets = (System.Int32 *)Marshal.AllocHGlobal(((int)numParts + 1) * sizeof(System.Int32));
                    subp_offsets = (System.Int32 *)Marshal.AllocHGlobal(((int)numSubparts + 1) * sizeof(System.Int32));
                    points       = (SE_POINT *)Marshal.AllocHGlobal((int)numPoints * sizeof(SE_POINT));

                    part_offsets[numParts]    = (int)numSubparts;
                    subp_offsets[numSubparts] = (int)numPoints;

                    err_no = Wrapper10.SE_shape_get_all_points(
                        shape_val,
                        SE_ROTATION_TYPE.SE_DEFAULT_ROTATION,
                        (IntPtr)part_offsets,
                        (IntPtr)subp_offsets,
                        (IntPtr)points,
                        (IntPtr)null,
                        (IntPtr)null);
                    if (err_no != 0)
                    {
                        return(null);
                    }

                    IGeometry ret = null;
                    switch (shapeType)
                    {
                    case CONST.SG_POINT_SHAPE:
                        if (numPoints == 1)
                        {
                            ret = new Point(points[0].x, points[0].y);
                        }
                        else if (numPoints > 1)
                        {
                            MultiPoint mPoint_ = new MultiPoint();
                            for (int i = 0; i < numPoints; i++)
                            {
                                mPoint_.AddPoint(new Point(points[i].x, points[i].y));
                            }
                            ret = mPoint_;
                        }
                        break;

                    case CONST.SG_MULTI_POINT_SHAPE:
                        MultiPoint mPoint = new MultiPoint();
                        for (int i = 0; i < numPoints; i++)
                        {
                            mPoint.AddPoint(new Point(points[i].x, points[i].y));
                        }
                        ret = mPoint;
                        break;

                    case CONST.SG_LINE_SHAPE:
                    case CONST.SG_SIMPLE_LINE_SHAPE:
                    case CONST.SG_MULTI_LINE_SHAPE:
                    case CONST.SG_MULTI_SIMPLE_LINE_SHAPE:
                        Polyline polyline = new Polyline();
                        for (int s = 0; s < numSubparts; s++)
                        {
                            Path path = new Path();
                            int  to   = subp_offsets[s + 1];
                            for (int i = subp_offsets[s]; i < to; i++)
                            {
                                path.AddPoint(new Point(points[i].x, points[i].y));
                            }
                            polyline.AddPath(path);
                        }
                        ret = polyline;
                        break;

                    case CONST.SG_AREA_SHAPE:
                    case CONST.SG_MULTI_AREA_SHAPE:
                        Polygon polygon = new Polygon();
                        for (int s = 0; s < numSubparts; s++)
                        {
                            Ring ring = new Ring();
                            int  to   = subp_offsets[s + 1];
                            for (int i = subp_offsets[s]; i < to; i++)
                            {
                                ring.AddPoint(new Point(points[i].x, points[i].y));
                            }
                            polygon.AddRing(ring);
                        }
                        ret = polygon;
                        break;
                    }
                    return(ret);
                }
                catch
                {
                    return(null);
                }
                finally
                {
                    if (part_offsets != null)
                    {
                        Marshal.FreeHGlobal((System.IntPtr)part_offsets);
                    }
                    if (subp_offsets != null)
                    {
                        Marshal.FreeHGlobal((System.IntPtr)subp_offsets);
                    }
                    if (points != null)
                    {
                        Marshal.FreeHGlobal((System.IntPtr)points);
                    }

                    if (shape_val.handle != IntPtr.Zero)
                    {
                        Wrapper10.SE_shape_free(shape_val);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        static public IGeometry AXL2Geometry(string axl, bool ignoreBuffer)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml("<g>" + axl + "</g>");

                AggregateGeometry aGeom = new AggregateGeometry();
                IPoint            point;

                XmlNode bufferNode = null;
                foreach (XmlNode node in doc.ChildNodes[0].ChildNodes)
                {
                    switch (node.Name)
                    {
                    case "BUFFER":
                        if (!ignoreBuffer)
                        {
                            bufferNode = node;
                        }
                        break;

                    case "POINT":
                        point = PointFromAxl(node);
                        AddSrs(node, point);
                        aGeom.AddGeometry(point);
                        break;

                    case "MULTIPOINT":
                        IMultiPoint mpoint = new MultiPoint();
                        AddSrs(node, mpoint);
                        foreach (XmlNode pointnode in node.SelectNodes("POINT"))
                        {
                            point = PointFromAxl(pointnode);
                            mpoint.AddPoint(point);
                        }
                        if (mpoint.PointCount == 0)
                        {
                            PointsFromCoords(mpoint, node.SelectSingleNode("COORDS"));
                        }
                        aGeom.AddGeometry(mpoint);
                        break;

                    case "ENVELOPE":
                        IEnvelope envelope = new Envelope(
                            Convert.ToDouble(node.Attributes["minx"].Value.Replace(".", ",")),
                            Convert.ToDouble(node.Attributes["miny"].Value.Replace(".", ",")),
                            Convert.ToDouble(node.Attributes["maxx"].Value.Replace(".", ",")),
                            Convert.ToDouble(node.Attributes["maxy"].Value.Replace(".", ",")));
                        AddSrs(node, envelope);
                        aGeom.AddGeometry(envelope);
                        break;

                    case "POLYLINE":
                        IPolyline pline = new Polyline();
                        AddSrs(node, pline);
                        foreach (XmlNode pathnode in node.SelectNodes("PATH"))
                        {
                            IPath path = new gView.Framework.Geometry.Path();
                            foreach (XmlNode pointnode in pathnode.SelectNodes("POINT"))
                            {
                                point = PointFromAxl(pointnode);
                                path.AddPoint(point);
                            }
                            foreach (XmlNode coordnode in pathnode.SelectNodes("COORDS"))
                            {
                                PointsFromCoords(path, coordnode);
                            }
                            pline.AddPath(path);
                        }
                        aGeom.AddGeometry(pline);
                        break;

                    case "POLYGON":
                        IPolygon pgon = new Polygon();
                        AddSrs(node, pgon);
                        foreach (XmlNode ringnode in node.SelectNodes("RING"))
                        {
                            IRing ring = new gView.Framework.Geometry.Ring();
                            foreach (XmlNode pointnode in ringnode.SelectNodes("POINT"))
                            {
                                point = PointFromAxl(pointnode);
                                ring.AddPoint(point);
                            }
                            foreach (XmlNode coordnode in ringnode.SelectNodes("COORDS"))
                            {
                                PointsFromCoords(ring, coordnode);
                            }
                            pgon.AddRing(ring);
                            foreach (XmlNode holenode in ringnode.SelectNodes("HOLE"))
                            {
                                IRing hole = new gView.Framework.Geometry.Ring();
                                foreach (XmlNode pointnode in holenode.SelectNodes("POINT"))
                                {
                                    point = PointFromAxl(pointnode);
                                    hole.AddPoint(point);
                                }
                                foreach (XmlNode coordnode in holenode.SelectNodes("COORDS"))
                                {
                                    PointsFromCoords(hole, coordnode);
                                }
                                pgon.AddRing(hole);
                            }
                        }
                        foreach (XmlNode ringnode in node.SelectNodes("HOLE"))
                        {
                            IRing ring = new gView.Framework.Geometry.Ring();
                            foreach (XmlNode pointnode in ringnode.SelectNodes("POINT"))
                            {
                                point = PointFromAxl(pointnode);
                                ring.AddPoint(point);
                            }
                            foreach (XmlNode coordnode in ringnode.SelectNodes("COORDS"))
                            {
                                PointsFromCoords(ring, coordnode);
                            }
                            pgon.AddRing(ring);
                        }
                        aGeom.AddGeometry(pgon);
                        break;
                    }
                }

                if (aGeom.GeometryCount == 0)
                {
                    return(null);
                }

                if (!ignoreBuffer &&
                    bufferNode != null && bufferNode.Attributes["distance"] != null)
                {
                    try
                    {
                        double   dist    = Convert.ToDouble(bufferNode.Attributes["distance"].Value);
                        IPolygon polygon = aGeom.Buffer(dist);
                        return(polygon);
                    }
                    catch { }
                }

                if (aGeom.GeometryCount == 1)
                {
                    return(aGeom[0]);
                }

                return(aGeom);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 7
0
        async private Task Query()
        {
            _features.Clear();

            string where = String.IsNullOrEmpty(_where) ?
                           $"{ _featureClass.IDFieldName }>{ _lastOid }" :
                           $"{ _where } and { _featureClass.IDFieldName }>{ _lastOid }";

            var postData = $"{ _postData }&orderByFields={ _featureClass.IDFieldName }&where={ where.UrlEncodeWhereClause() }";

            var jsonFeatureResponse = await _dataset.TryPostAsync <JsonFeatureResponse>(_queryUrl, postData);

            #region Parse Field Types (eg. is Date?)

            List <string> dateColumns = new List <string>();
            if (_featureClass?.Fields != null)
            {
                foreach (var field in _featureClass.Fields.ToEnumerable())
                {
                    if (field.type == FieldType.Date)
                    {
                        dateColumns.Add(field.name);
                    }
                }
            }

            #endregion

            foreach (var jsonFeature in jsonFeatureResponse.Features)
            {
                Feature feature = new Feature();

                #region Geometry

                if (_featureClass.GeometryType == geometryType.Polyline && jsonFeature.Geometry?.Paths != null)
                {
                    Polyline polyline = new Polyline();
                    for (int p = 0, to = jsonFeature.Geometry.Paths.Length; p < to; p++)
                    {
                        Path path = new Path();

                        var pathsPointsArray       = jsonFeature.Geometry.Paths[p];
                        var dimension              = pathsPointsArray.GetLength(1); // 2D 3D 3D+M ?
                        int pathsPointsArrayLength = (pathsPointsArray.Length / dimension);

                        for (int multiArrayIndex = 0; multiArrayIndex < pathsPointsArrayLength; multiArrayIndex++)
                        {
                            path.AddPoint(ArrayToPoint(pathsPointsArray, multiArrayIndex, dimension));
                        }
                        polyline.AddPath(path);
                    }

                    feature.Shape = polyline;
                }
                else if (_featureClass.GeometryType == geometryType.Polygon && jsonFeature.Geometry?.Rings != null)
                {
                    Polygon polygon = new Polygon();
                    for (int r = 0, to = jsonFeature.Geometry.Rings.Length; r < to; r++)
                    {
                        Ring ring = new Ring();

                        var ringsPointsArray       = jsonFeature.Geometry.Rings[r];
                        var dimension              = ringsPointsArray.GetLength(1); // 2D 3D 3D+M ?
                        int ringsPointsArrayLength = (ringsPointsArray.Length / dimension);

                        for (int multiArrayIndex = 0; multiArrayIndex < ringsPointsArrayLength; multiArrayIndex++)
                        {
                            //Point point = new Point();
                            //point.X = ringsPointsArray[multiArrayIndex, 0];
                            //point.Y = ringsPointsArray[multiArrayIndex, 1];

                            ring.AddPoint(ArrayToPoint(ringsPointsArray, multiArrayIndex, dimension));
                        }
                        polygon.AddRing(ring);
                    }

                    feature.Shape = polygon;
                }
                else if (_featureClass.GeometryType == geometryType.Point &&
                         (jsonFeature.Geometry?.X != null) &&
                         (jsonFeature.Geometry?.Y != null)
                         )
                {
                    Point shape = _featureClass.HasM ? new PointM() : new Point();
                    shape.X = jsonFeature.Geometry.X.Value;
                    shape.Y = jsonFeature.Geometry.Y.Value;

                    if (_featureClass.HasZ && jsonFeature.Geometry.Z.HasValue)
                    {
                        shape.Z = jsonFeature.Geometry.Z.Value;
                    }

                    if (this._featureClass.HasM && jsonFeature.Geometry.M.HasValue)
                    {
                        ((PointM)shape).M = jsonFeature.Geometry.M.Value;
                    }

                    feature.Shape = shape;
                }
                else if (_featureClass.GeometryType == geometryType.Multipoint &&
                         jsonFeature.Geometry?.Points != null &&
                         jsonFeature.Geometry.Points.Length > 0)
                {
                    MultiPoint multiPoint = new MultiPoint();

                    for (int p = 0, pointCount = jsonFeature.Geometry.Points.Length; p < pointCount; p++)
                    {
                        var doubleArray = jsonFeature.Geometry.Points[p];
                        if (doubleArray.Length >= 2)
                        {
                            var point = new Point(doubleArray[0].Value, doubleArray[1].Value);

                            multiPoint.AddPoint(point);
                        }
                    }

                    feature.Shape = multiPoint;
                }
                else
                {
                }

                #endregion

                #region Properties

                if (jsonFeature.Attributes != null)
                {
                    var attribiutes = (IDictionary <string, object>)jsonFeature.Attributes;
                    foreach (var name in attribiutes.Keys)
                    {
                        object value = attribiutes[name];

                        if (dateColumns.Contains(name))
                        {
                            try
                            {
                                long     esriDate = Convert.ToInt64(value);
                                DateTime td       = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(esriDate);
                                feature.Fields.Add(new FieldValue(name, td));
                            }
                            catch // if date is not a long?!
                            {
                                feature.Fields.Add(new FieldValue(name, value?.ToString()));
                            }
                        }
                        else
                        {
                            //if (!filter.SuppressResolveAttributeDomains && _domains != null && _domains.ContainsKey(name))
                            //{
                            //    value = DomainValue(name, value?.ToString());
                            //}
                            feature.Fields.Add(new FieldValue(name, value?.ToString()));
                        }

                        if (name == _featureClass.IDFieldName)
                        {
                            feature.OID = int.Parse(value.ToString());
                            _lastOid    = Math.Max(_lastOid, feature.OID);
                        }
                    }
                }

                #endregion

                _features.Add(feature);
            }

            _hasMore = _lastOid > 0 && jsonFeatureResponse.ExceededTransferLimit;

            //_hasMore = false;
        }
Ejemplo n.º 8
0
        static public IGeometry ToGeometry(this JsonGeometry geometry)
        {
            if (geometry == null)
            {
                return(null);
            }

            IGeometry shape = null;

            if (geometry.X.HasValue && geometry.Y.HasValue)
            {
                shape = new Point(geometry.X.Value, geometry.Y.Value);
            }
            else if (geometry.XMin.HasValue && geometry.YMin.HasValue && geometry.XMax.HasValue && geometry.YMax.HasValue)
            {
                shape = new Envelope(geometry.XMin.Value, geometry.YMin.Value, geometry.XMax.Value, geometry.YMax.Value);
            }
            else if (geometry.Paths != null && geometry.Paths.Length > 0)
            {
                var polyline = new Polyline();

                for (int p = 0, pathCount = geometry.Paths.Length; p < pathCount; p++)
                {
                    var jsonPath = geometry.Paths[p];
                    if (jsonPath.Length < 1)
                    {
                        continue;
                    }

                    var path = new Path();
                    for (int i = 0, pointCount = jsonPath.GetLength(0); i < pointCount; i++)
                    {
                        path.AddPoint(new Point(jsonPath[i, 0].Value, jsonPath[i, 1].Value));
                    }
                    polyline.AddPath(path);
                }

                shape = polyline;
            }
            else if (geometry.Rings != null && geometry.Rings.Length > 0)
            {
                var polygon = new Polygon();

                for (int p = 0, ringCount = geometry.Rings.Length; p < ringCount; p++)
                {
                    var jsonRing = geometry.Rings[p];
                    if (jsonRing.Length < 1)
                    {
                        continue;
                    }

                    var ring = new Ring();
                    for (int i = 0, pointCount = jsonRing.GetLength(0); i < pointCount; i++)
                    {
                        ring.AddPoint(new Point(jsonRing[i, 0].Value, jsonRing[i, 1].Value));
                    }
                    polygon.AddRing(ring);
                }

                shape = polygon;
            }
            else if (geometry.Points != null && geometry.Points.Length > 0)
            {
                var multiPoint = new MultiPoint();

                for (int p = 0, pointCount = geometry.Points.Length; p < pointCount; p++)
                {
                    var point = geometry.Points[p];
                    if (point != null && point.Length >= 2)
                    {
                        multiPoint.AddPoint(new Point(point[0].Value, point[1].Value));
                    }
                }

                shape = multiPoint;
            }

            if (shape != null && geometry.SpatialReference != null && geometry.SpatialReference.Wkid > 0)
            {
                shape.Srs = geometry.SpatialReference.Wkid;
            }

            return(shape);
        }