Example #1
0
 /// <exception cref="java.io.ObjectStreamException"/>
 internal object ReadResolve()
 {
     com.epl.geometry.Geometry geometry = null;
     try
     {
         geometry = com.epl.geometry.GeometryEngine.GeometryFromEsriShape(geometryData.esriShape, geometryData.geometryType);
         if (com.epl.geometry.Geometry.IsMultiVertex(geometry.GetType().Value()))
         {
             com.epl.geometry.GeometrySerializer.MultiVertexData mvd    = (com.epl.geometry.GeometrySerializer.MultiVertexData)geometryData;
             com.epl.geometry.MultiVertexGeometryImpl            mvImpl = (com.epl.geometry.MultiVertexGeometryImpl)geometry._getImpl();
             if (!geometry.IsEmpty() && com.epl.geometry.Geometry.IsMultiPath(geometry.GetType().Value()))
             {
                 com.epl.geometry.GeometrySerializer.MultiPathData mpd = (com.epl.geometry.GeometrySerializer.MultiPathData)geometryData;
                 com.epl.geometry.MultiPathImpl         mpImpl         = (com.epl.geometry.MultiPathImpl)geometry._getImpl();
                 com.epl.geometry.AttributeStreamOfInt8 pathFlags      = mpImpl.GetPathFlagsStreamRef();
                 for (int i = 0, n = mpImpl.GetPathCount(); i < n; i++)
                 {
                     if (mpd.ogcFlags[i])
                     {
                         pathFlags.SetBits(i, unchecked ((byte)com.epl.geometry.PathFlags.enumOGCStartPolygon));
                     }
                 }
             }
             mvImpl.SetIsSimple(mvd.simpleFlag, mvd.tolerance, false);
         }
     }
     catch (System.Exception)
     {
         throw new System.IO.InvalidDataException("Cannot read geometry from stream");
     }
     return(geometry);
 }
Example #2
0
        /// <summary>
        /// Appends points from another MultiVertexGeometryImpl at the end of this
        /// one.
        /// </summary>
        /// <param name="src">The source MultiVertexGeometryImpl</param>
        public void Add(com.epl.geometry.MultiVertexGeometryImpl src, int beginIndex, int endIndex)
        {
            int endIndexC = endIndex < 0 ? src.GetPointCount() : endIndex;

            if (beginIndex < 0 || beginIndex > src.GetPointCount() || endIndexC < beginIndex)
            {
                throw new System.ArgumentException();
            }
            if (beginIndex == endIndexC)
            {
                return;
            }
            MergeVertexDescription(src.GetDescription());
            int count         = endIndexC - beginIndex;
            int oldPointCount = m_pointCount;

            Resize(m_pointCount + count);
            _verifyAllStreams();
            for (int iattrib = 0, nattrib = src.GetDescription().GetAttributeCount(); iattrib < nattrib; iattrib++)
            {
                int semantics = src.GetDescription()._getSemanticsImpl(iattrib);
                int ncomps    = com.epl.geometry.VertexDescription.GetComponentCount(semantics);
                com.epl.geometry.AttributeStreamBase stream    = GetAttributeStreamRef(semantics);
                com.epl.geometry.AttributeStreamBase srcStream = src.GetAttributeStreamRef(semantics);
                stream.InsertRange(oldPointCount * ncomps, srcStream, beginIndex * ncomps, count * ncomps, true, 1, oldPointCount * ncomps);
            }
        }
 private static int QuickTest2DMVEnvelopeRasterOnly(com.epl.geometry.MultiVertexGeometry geomA, com.epl.geometry.Envelope2D geomBEnv, double tolerance)
 {
     // Use rasterized Geometry only:
     com.epl.geometry.RasterizedGeometry2D    rgeomA;
     com.epl.geometry.MultiVertexGeometryImpl mpImpl = (com.epl.geometry.MultiVertexGeometryImpl)geomA._getImpl();
     com.epl.geometry.GeometryAccelerators    gaccel = mpImpl._getAccelerators();
     if (gaccel != null)
     {
         rgeomA = gaccel.GetRasterizedGeometry();
     }
     else
     {
         return(-1);
     }
     if (rgeomA != null)
     {
         com.epl.geometry.RasterizedGeometry2D.HitType hitres = rgeomA.QueryEnvelopeInGeometry(geomBEnv);
         if (hitres == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
         {
             return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
         }
         if (hitres == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
         {
             return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains);
         }
     }
     else
     {
         return(-1);
     }
     return(0);
 }
Example #4
0
        internal virtual com.epl.geometry.Proximity2DResult MultiVertexGetNearestVertex(com.epl.geometry.MultiVertexGeometry geom, com.epl.geometry.Point2D inputPoint)
        {
            com.epl.geometry.MultiVertexGeometryImpl mpImpl   = (com.epl.geometry.MultiVertexGeometryImpl)geom._getImpl();
            com.epl.geometry.AttributeStreamOfDbl    position = (com.epl.geometry.AttributeStreamOfDbl)mpImpl.GetAttributeStreamRef((com.epl.geometry.VertexDescription.Semantics.POSITION));
            int    pointCount        = geom.GetPointCount();
            int    closestIndex      = 0;
            double closestx          = 0.0;
            double closesty          = 0.0;
            double closestDistanceSq = com.epl.geometry.NumberUtils.DoubleMax();

            for (int i = 0; i < pointCount; i++)
            {
                com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
                position.Read(2 * i, pt);
                double distanceSq = com.epl.geometry.Point2D.SqrDistance(pt, inputPoint);
                if (distanceSq < closestDistanceSq)
                {
                    closestx          = pt.x;
                    closesty          = pt.y;
                    closestIndex      = i;
                    closestDistanceSq = distanceSq;
                }
            }
            com.epl.geometry.Proximity2DResult result = new com.epl.geometry.Proximity2DResult();
            result._setParams(closestx, closesty, closestIndex, System.Math.Sqrt(closestDistanceSq));
            return(result);
        }
Example #5
0
 /// <exception cref="java.io.ObjectStreamException"/>
 public virtual void SetGeometryByValue(com.epl.geometry.Geometry geometry)
 {
     try
     {
         esriShape    = com.epl.geometry.GeometryEngine.GeometryToEsriShape(geometry);
         geometryType = geometry.GetType().Value();
         if (com.epl.geometry.Geometry.IsMultiVertex(geometryType))
         {
             com.epl.geometry.MultiVertexGeometryImpl mvImpl = (com.epl.geometry.MultiVertexGeometryImpl)geometry._getImpl();
             tolerance  = mvImpl.m_simpleTolerance;
             simpleFlag = mvImpl.GetIsSimple(0);
             if (!geometry.IsEmpty() && com.epl.geometry.Geometry.IsMultiPath(geometryType))
             {
                 com.epl.geometry.MultiPathImpl mpImpl = (com.epl.geometry.MultiPathImpl)geometry._getImpl();
                 ogcFlags = new bool[mpImpl.GetPathCount()];
                 com.epl.geometry.AttributeStreamOfInt8 pathFlags = mpImpl.GetPathFlagsStreamRef();
                 for (int i = 0, n = mpImpl.GetPathCount(); i < n; i++)
                 {
                     ogcFlags[i] = (pathFlags.Read(i) & unchecked ((byte)com.epl.geometry.PathFlags.enumOGCStartPolygon)) != 0;
                 }
             }
         }
     }
     catch (System.Exception)
     {
         throw new System.IO.InvalidDataException("Cannot serialize this geometry");
     }
 }
 public override void CopyTo(com.epl.geometry.Geometry dstGeom)
 {
     com.epl.geometry.MultiVertexGeometryImpl dst = (com.epl.geometry.MultiVertexGeometryImpl)dstGeom;
     if (dst.GetType() != GetType())
     {
         throw new System.ArgumentException();
     }
     _copyToUnsafe(dst);
 }
 internal static com.epl.geometry.RasterizedGeometry2D Create(com.epl.geometry.MultiVertexGeometryImpl geom, double toleranceXY, int rasterSizeBytes)
 {
     if (!CanUseAccelerator(geom))
     {
         throw new System.ArgumentException();
     }
     com.epl.geometry.RasterizedGeometry2DImpl gc = com.epl.geometry.RasterizedGeometry2DImpl.CreateImpl(geom, toleranceXY, rasterSizeBytes);
     return((com.epl.geometry.RasterizedGeometry2D)gc);
 }
        internal void ShiftPath(com.epl.geometry.MultiPath inputGeom, int iPath, double shift)
        {
            com.epl.geometry.MultiVertexGeometryImpl vertexGeometryImpl = (com.epl.geometry.MultiVertexGeometryImpl)inputGeom._getImpl();
            com.epl.geometry.AttributeStreamOfDbl    xyStream           = (com.epl.geometry.AttributeStreamOfDbl)vertexGeometryImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
            int i1 = inputGeom.GetPathStart(iPath);
            int i2 = inputGeom.GetPathEnd(iPath);

            com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
            while (i1 < i2)
            {
                xyStream.Read(i1, pt);
                pt.x += shift;
                xyStream.Write(i1, pt);
                i1++;
            }
        }
        // Checked vs. Jan 11, 2011
        public override bool Equals(object other)
        {
            // Java checks
            if (other == this)
            {
                return(true);
            }
            if (!(other is com.epl.geometry.MultiVertexGeometryImpl))
            {
                return(false);
            }
            com.epl.geometry.MultiVertexGeometryImpl otherMulti = (com.epl.geometry.MultiVertexGeometryImpl)other;
            if (!(m_description.Equals(otherMulti.m_description)))
            {
                return(false);
            }
            if (IsEmptyImpl() != otherMulti.IsEmptyImpl())
            {
                return(false);
            }
            if (IsEmptyImpl())
            {
                return(true);
            }
            // both geometries are empty
            int pointCount      = GetPointCount();
            int pointCountOther = otherMulti.GetPointCount();

            if (pointCount != pointCountOther)
            {
                return(false);
            }
            for (int i = 0; i < m_description.GetAttributeCount(); i++)
            {
                int semantics = m_description.GetSemantics(i);
                com.epl.geometry.AttributeStreamBase stream      = GetAttributeStreamRef(semantics);
                com.epl.geometry.AttributeStreamBase streamOther = otherMulti.GetAttributeStreamRef(semantics);
                int components = com.epl.geometry.VertexDescription.GetComponentCount(semantics);
                if (!stream.Equals(streamOther, 0, pointCount * components))
                {
                    return(false);
                }
            }
            return(true);
        }
        //Does not check geometry type. Used to copy Polygon to Polyline
        internal virtual void _copyToUnsafe(com.epl.geometry.MultiVertexGeometryImpl dst)
        {
            _verifyAllStreams();
            dst.m_description      = m_description;
            dst.m_vertexAttributes = null;
            int nattrib = m_description.GetAttributeCount();

            com.epl.geometry.AttributeStreamBase[] cloneAttributes = null;
            if (m_vertexAttributes != null)
            {
                cloneAttributes = new com.epl.geometry.AttributeStreamBase[nattrib];
                for (int i = 0; i < nattrib; i++)
                {
                    if (m_vertexAttributes[i] != null)
                    {
                        int ncomps = com.epl.geometry.VertexDescription.GetComponentCount(m_description._getSemanticsImpl(i));
                        cloneAttributes[i] = m_vertexAttributes[i].RestrictedClone(GetPointCount() * ncomps);
                    }
                }
            }
            if (m_envelope != null)
            {
                dst.m_envelope = (com.epl.geometry.Envelope)m_envelope.CreateInstance();
                m_envelope.CopyTo(dst.m_envelope);
            }
            else
            {
                // dst.m_envelope = (Envelope) m_envelope.clone();
                dst.m_envelope = null;
            }
            dst.m_pointCount       = m_pointCount;
            dst.m_flagsMask        = m_flagsMask;
            dst.m_vertexAttributes = cloneAttributes;
            try
            {
                _copyToImpl(dst);
            }
            catch (System.Exception ex)
            {
                // copy child props
                dst.SetEmpty();
                throw new System.Exception("", ex);
            }
        }
Example #11
0
        internal virtual com.epl.geometry.Proximity2DResult[] MultiVertexGetNearestVertices(com.epl.geometry.MultiVertexGeometry geom, com.epl.geometry.Point2D inputPoint, double searchRadius, int maxVertexCountToReturn)
        {
            com.epl.geometry.Proximity2DResult[] resultArray;
            if (maxVertexCountToReturn == 0)
            {
                resultArray = new com.epl.geometry.Proximity2DResult[0];
                return(resultArray);
            }
            com.epl.geometry.MultiVertexGeometryImpl mpImpl   = (com.epl.geometry.MultiVertexGeometryImpl)geom._getImpl();
            com.epl.geometry.AttributeStreamOfDbl    position = (com.epl.geometry.AttributeStreamOfDbl)mpImpl.GetAttributeStreamRef((com.epl.geometry.VertexDescription.Semantics.POSITION));
            int pointCount = geom.GetPointCount();

            System.Collections.Generic.List <com.epl.geometry.Proximity2DResult> v = new System.Collections.Generic.List <com.epl.geometry.Proximity2DResult>(maxVertexCountToReturn);
            int    count          = 0;
            double searchRadiusSq = searchRadius * searchRadius;

            for (int i = 0; i < pointCount; i++)
            {
                double x          = position.Read(2 * i);
                double y          = position.Read(2 * i + 1);
                double xDiff      = inputPoint.x - x;
                double yDiff      = inputPoint.y - y;
                double distanceSq = xDiff * xDiff + yDiff * yDiff;
                if (distanceSq <= searchRadiusSq)
                {
                    com.epl.geometry.Proximity2DResult result = new com.epl.geometry.Proximity2DResult();
                    result._setParams(x, y, i, System.Math.Sqrt(distanceSq));
                    count++;
                    v.Add(result);
                }
            }
            int vsize = v.Count;

            v.Sort(new com.epl.geometry.Proximity2DResultComparator());
            if (maxVertexCountToReturn >= vsize)
            {
                return(v.ToArray());
            }
            return(v.GetRange(0, maxVertexCountToReturn - 0).ToArray());
        }
 // TODO Remove?
 /// <summary>\internal CHildren implement this method to copy additional information</summary>
 internal abstract void _copyToImpl(com.epl.geometry.MultiVertexGeometryImpl mvg);
        internal void Init(com.epl.geometry.MultiVertexGeometryImpl geom, double toleranceXY, int rasterSizeBytes)
        {
            // _ASSERT(CanUseAccelerator(geom));
            m_width        = System.Math.Max((int)(System.Math.Sqrt(rasterSizeBytes) * 2 + 0.5), 64);
            m_scanLineSize = (m_width * 2 + 31) / 32;
            // 2 bits per pixel
            m_geomEnv     = new com.epl.geometry.Envelope2D();
            m_toleranceXY = toleranceXY;
            // calculate bitmap size
            int size         = 0;
            int width        = m_width;
            int scanLineSize = m_scanLineSize;

            while (width >= 8)
            {
                size        += width * scanLineSize;
                width       /= 2;
                scanLineSize = (width * 2 + 31) / 32;
            }
            // allocate the bitmap, that contains the base and the mip-levels
            m_bitmap = new int[size];
            for (int i = 0; i < size; i++)
            {
                m_bitmap[i] = 0;
            }
            m_rasterizer = new com.epl.geometry.SimpleRasterizer();
            com.epl.geometry.RasterizedGeometry2DImpl.ScanCallbackImpl callback = new com.epl.geometry.RasterizedGeometry2DImpl.ScanCallbackImpl(this, m_bitmap, m_scanLineSize);
            m_callback = callback;
            m_rasterizer.Setup(m_width, m_width, callback);
            geom.QueryEnvelope2D(m_geomEnv);
            if (m_geomEnv.GetWidth() > m_width * m_geomEnv.GetHeight() || m_geomEnv.GetHeight() > m_geomEnv.GetWidth() * m_width)
            {
            }
            // the geometry is thin and the rasterizer is not needed.
            m_geomEnv.Inflate(toleranceXY, toleranceXY);
            com.epl.geometry.Envelope2D worldEnv = new com.epl.geometry.Envelope2D();
            com.epl.geometry.Envelope2D pixEnv   = com.epl.geometry.Envelope2D.Construct(1, 1, m_width - 2, m_width - 2);
            double minWidth = toleranceXY * pixEnv.GetWidth();
            // min width is such
            // that the size of
            // one pixel is
            // equal to the
            // tolerance
            double minHeight = toleranceXY * pixEnv.GetHeight();

            worldEnv.SetCoords(m_geomEnv.GetCenter(), System.Math.Max(minWidth, m_geomEnv.GetWidth()), System.Math.Max(minHeight, m_geomEnv.GetHeight()));
            m_stroke_half_widthX_pix = worldEnv.GetWidth() / pixEnv.GetWidth();
            m_stroke_half_widthY_pix = worldEnv.GetHeight() / pixEnv.GetHeight();
            // The stroke half width. Later it will be inflated to account for
            // pixels size.
            m_stroke_half_width = m_toleranceXY;
            m_transform         = new com.epl.geometry.Transformation2D();
            m_transform.InitializeFromRect(worldEnv, pixEnv);
            // geom to pixels
            com.epl.geometry.Transformation2D identityTransform = new com.epl.geometry.Transformation2D();
            switch (geom.GetType().Value())
            {
            case com.epl.geometry.Geometry.GeometryType.MultiPoint:
            {
                callback.SetColor(m_rasterizer, 2);
                FillPoints(m_rasterizer, (com.epl.geometry.MultiPointImpl)geom, m_stroke_half_width);
                break;
            }

            case com.epl.geometry.Geometry.GeometryType.Polyline:
            {
                callback.SetColor(m_rasterizer, 2);
                StrokeDrawPolyPath(m_rasterizer, (com.epl.geometry.MultiPathImpl)geom._getImpl(), m_stroke_half_width);
                break;
            }

            case com.epl.geometry.Geometry.GeometryType.Polygon:
            {
                bool isWinding = false;
                // NOTE: change when winding is supported
                callback.SetColor(m_rasterizer, 1);
                FillMultiPath(m_rasterizer, m_transform, (com.epl.geometry.MultiPathImpl)geom, isWinding);
                callback.SetColor(m_rasterizer, 2);
                StrokeDrawPolyPath(m_rasterizer, (com.epl.geometry.MultiPathImpl)geom._getImpl(), m_stroke_half_width);
                break;
            }
            }
            m_dx = m_transform.xx;
            m_dy = m_transform.yy;
            m_x0 = m_transform.xd;
            m_y0 = m_transform.yd;
            BuildLevels();
        }
        public static int QuickTest2D_Accelerated_DisjointOrContains(com.epl.geometry.Geometry geomA, com.epl.geometry.Geometry geomB, double tolerance)
        {
            int gtA = geomA.GetType().Value();
            int gtB = geomB.GetType().Value();

            com.epl.geometry.GeometryAccelerators accel;
            bool endWhileStatement = false;

            do
            {
                if (com.epl.geometry.Geometry.IsMultiVertex(gtA))
                {
                    com.epl.geometry.MultiVertexGeometryImpl impl = (com.epl.geometry.MultiVertexGeometryImpl)geomA._getImpl();
                    accel = impl._getAccelerators();
                    if (accel != null)
                    {
                        com.epl.geometry.RasterizedGeometry2D rgeom = accel.GetRasterizedGeometry();
                        if (rgeom != null)
                        {
                            if (gtB == com.epl.geometry.Geometry.GeometryType.Point)
                            {
                                com.epl.geometry.Point2D ptB = ((com.epl.geometry.Point)geomB).GetXY();
                                com.epl.geometry.RasterizedGeometry2D.HitType hit = rgeom.QueryPointInGeometry(ptB.x, ptB.y);
                                if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
                                {
                                    return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains);
                                }
                                else
                                {
                                    if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
                                    {
                                        return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
                                    }
                                }
                                break;
                            }
                            com.epl.geometry.Envelope2D envB = new com.epl.geometry.Envelope2D();
                            geomB.QueryEnvelope2D(envB);
                            com.epl.geometry.RasterizedGeometry2D.HitType hit_1 = rgeom.QueryEnvelopeInGeometry(envB);
                            if (hit_1 == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
                            {
                                return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains);
                            }
                            else
                            {
                                if (hit_1 == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
                                {
                                    return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
                                }
                            }
                            break;
                        }
                    }
                }
            }while (endWhileStatement);
            accel = null;
            do
            {
                if (com.epl.geometry.Geometry.IsMultiVertex(gtB))
                {
                    com.epl.geometry.MultiVertexGeometryImpl impl = (com.epl.geometry.MultiVertexGeometryImpl)geomB._getImpl();
                    accel = impl._getAccelerators();
                    if (accel != null)
                    {
                        com.epl.geometry.RasterizedGeometry2D rgeom = accel.GetRasterizedGeometry();
                        if (rgeom != null)
                        {
                            if (gtA == com.epl.geometry.Geometry.GeometryType.Point)
                            {
                                com.epl.geometry.Point2D ptA = ((com.epl.geometry.Point)geomA).GetXY();
                                com.epl.geometry.RasterizedGeometry2D.HitType hit = rgeom.QueryPointInGeometry(ptA.x, ptA.y);
                                if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
                                {
                                    return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Within);
                                }
                                else
                                {
                                    if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
                                    {
                                        return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
                                    }
                                }
                                break;
                            }
                            com.epl.geometry.Envelope2D envA = new com.epl.geometry.Envelope2D();
                            geomA.QueryEnvelope2D(envA);
                            com.epl.geometry.RasterizedGeometry2D.HitType hit_1 = rgeom.QueryEnvelopeInGeometry(envA);
                            if (hit_1 == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
                            {
                                return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Within);
                            }
                            else
                            {
                                if (hit_1 == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
                                {
                                    return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
                                }
                            }
                            break;
                        }
                    }
                }
            }while (endWhileStatement);
            return(0);
        }
 internal static com.epl.geometry.MapGeometry ImportFromJsonParser(int gt, com.epl.geometry.JsonReader parser)
 {
     com.epl.geometry.MapGeometry mp;
     try
     {
         if (!com.epl.geometry.JSONUtils.IsObjectStart(parser))
         {
             return(null);
         }
         bool   bFoundSpatial_reference = false;
         bool   bFoundHasZ       = false;
         bool   bFoundHasM       = false;
         bool   bFoundPolygon    = false;
         bool   bFoundPolyline   = false;
         bool   bFoundMultiPoint = false;
         bool   bFoundX          = false;
         bool   bFoundY          = false;
         bool   bFoundZ          = false;
         bool   bFoundM          = false;
         bool   bFoundXMin       = false;
         bool   bFoundYMin       = false;
         bool   bFoundXMax       = false;
         bool   bFoundYMax       = false;
         bool   bFoundZMin       = false;
         bool   bFoundZMax       = false;
         bool   bFoundMMin       = false;
         bool   bFoundMMax       = false;
         double x     = com.epl.geometry.NumberUtils.NaN();
         double y     = com.epl.geometry.NumberUtils.NaN();
         double z     = com.epl.geometry.NumberUtils.NaN();
         double m     = com.epl.geometry.NumberUtils.NaN();
         double xmin  = com.epl.geometry.NumberUtils.NaN();
         double ymin  = com.epl.geometry.NumberUtils.NaN();
         double xmax  = com.epl.geometry.NumberUtils.NaN();
         double ymax  = com.epl.geometry.NumberUtils.NaN();
         double zmin  = com.epl.geometry.NumberUtils.NaN();
         double zmax  = com.epl.geometry.NumberUtils.NaN();
         double mmin  = com.epl.geometry.NumberUtils.NaN();
         double mmax  = com.epl.geometry.NumberUtils.NaN();
         bool   bHasZ = false;
         bool   bHasM = false;
         com.epl.geometry.AttributeStreamOfDbl @as               = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0);
         com.epl.geometry.AttributeStreamOfDbl bs                = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0);
         com.epl.geometry.Geometry             geometry          = null;
         com.epl.geometry.SpatialReference     spatial_reference = null;
         while (parser.NextToken() != com.epl.geometry.JsonReader.Token.END_OBJECT)
         {
             string name = parser.CurrentString();
             parser.NextToken();
             if (!bFoundSpatial_reference && name.Equals("spatialReference"))
             {
                 bFoundSpatial_reference = true;
                 if (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.START_OBJECT)
                 {
                     spatial_reference = com.epl.geometry.SpatialReference.FromJson(parser);
                 }
                 else
                 {
                     if (parser.CurrentToken() != com.epl.geometry.JsonReader.Token.VALUE_NULL)
                     {
                         throw new com.epl.geometry.GeometryException("failed to parse spatial reference: object or null is expected");
                     }
                 }
             }
             else
             {
                 if (!bFoundHasZ && name.Equals("hasZ"))
                 {
                     bFoundHasZ = true;
                     bHasZ      = (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.VALUE_TRUE);
                 }
                 else
                 {
                     if (!bFoundHasM && name.Equals("hasM"))
                     {
                         bFoundHasM = true;
                         bHasM      = (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.VALUE_TRUE);
                     }
                     else
                     {
                         if (!bFoundPolygon && name.Equals("rings") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Polygon))
                         {
                             bFoundPolygon = true;
                             geometry      = ImportFromJsonMultiPath(true, parser, @as, bs);
                             continue;
                         }
                         else
                         {
                             if (!bFoundPolyline && name.Equals("paths") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Polyline))
                             {
                                 bFoundPolyline = true;
                                 geometry       = ImportFromJsonMultiPath(false, parser, @as, bs);
                                 continue;
                             }
                             else
                             {
                                 if (!bFoundMultiPoint && name.Equals("points") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.MultiPoint))
                                 {
                                     bFoundMultiPoint = true;
                                     geometry         = ImportFromJsonMultiPoint(parser, @as, bs);
                                     continue;
                                 }
                                 else
                                 {
                                     if (!bFoundX && name.Equals("x") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point))
                                     {
                                         bFoundX = true;
                                         x       = ReadDouble(parser);
                                     }
                                     else
                                     {
                                         if (!bFoundY && name.Equals("y") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point))
                                         {
                                             bFoundY = true;
                                             y       = ReadDouble(parser);
                                         }
                                         else
                                         {
                                             if (!bFoundZ && name.Equals("z") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point))
                                             {
                                                 bFoundZ = true;
                                                 z       = ReadDouble(parser);
                                             }
                                             else
                                             {
                                                 if (!bFoundM && name.Equals("m") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point))
                                                 {
                                                     bFoundM = true;
                                                     m       = ReadDouble(parser);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!bFoundXMin && name.Equals("xmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope))
             {
                 bFoundXMin = true;
                 xmin       = ReadDouble(parser);
             }
             else
             {
                 if (!bFoundYMin && name.Equals("ymin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope))
                 {
                     bFoundYMin = true;
                     ymin       = ReadDouble(parser);
                 }
                 else
                 {
                     if (!bFoundMMin && name.Equals("mmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope))
                     {
                         bFoundMMin = true;
                         mmin       = ReadDouble(parser);
                     }
                     else
                     {
                         if (!bFoundZMin && name.Equals("zmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope))
                         {
                             bFoundZMin = true;
                             zmin       = ReadDouble(parser);
                         }
                         else
                         {
                             if (!bFoundXMax && name.Equals("xmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope))
                             {
                                 bFoundXMax = true;
                                 xmax       = ReadDouble(parser);
                             }
                             else
                             {
                                 if (!bFoundYMax && name.Equals("ymax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope))
                                 {
                                     bFoundYMax = true;
                                     ymax       = ReadDouble(parser);
                                 }
                                 else
                                 {
                                     if (!bFoundMMax && name.Equals("mmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope))
                                     {
                                         bFoundMMax = true;
                                         mmax       = ReadDouble(parser);
                                     }
                                     else
                                     {
                                         if (!bFoundZMax && name.Equals("zmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope))
                                         {
                                             bFoundZMax = true;
                                             zmax       = ReadDouble(parser);
                                         }
                                         else
                                         {
                                             Windup(parser);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (bFoundPolygon || bFoundPolyline || bFoundMultiPoint)
         {
             System.Diagnostics.Debug.Assert((geometry != null));
             com.epl.geometry.MultiVertexGeometryImpl mvImpl = (com.epl.geometry.MultiVertexGeometryImpl)geometry._getImpl();
             com.epl.geometry.AttributeStreamBase     zs     = null;
             com.epl.geometry.AttributeStreamBase     ms     = null;
             if (bHasZ)
             {
                 geometry.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                 zs = @as;
             }
             if (bHasM)
             {
                 geometry.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                 ms = !bHasZ ? @as : bs;
             }
             if (bHasZ && zs != null)
             {
                 mvImpl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z, zs);
             }
             if (bHasM && ms != null)
             {
                 mvImpl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M, ms);
             }
             mvImpl.NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyAll);
         }
         else
         {
             if (bFoundX || bFoundY || bFoundY || bFoundZ)
             {
                 if (com.epl.geometry.NumberUtils.IsNaN(y))
                 {
                     x = com.epl.geometry.NumberUtils.NaN();
                 }
                 com.epl.geometry.Point p = new com.epl.geometry.Point(x, y);
                 if (bFoundZ)
                 {
                     p.SetZ(z);
                 }
                 if (bFoundM)
                 {
                     p.SetM(m);
                 }
                 geometry = p;
             }
             else
             {
                 if (bFoundXMin || bFoundYMin || bFoundXMax || bFoundYMax || bFoundZMin || bFoundZMax || bFoundMMin || bFoundMMax)
                 {
                     if (com.epl.geometry.NumberUtils.IsNaN(ymin) || com.epl.geometry.NumberUtils.IsNaN(xmax) || com.epl.geometry.NumberUtils.IsNaN(ymax))
                     {
                         xmin = com.epl.geometry.NumberUtils.NaN();
                     }
                     com.epl.geometry.Envelope e = new com.epl.geometry.Envelope(xmin, ymin, xmax, ymax);
                     if (bFoundZMin && bFoundZMax)
                     {
                         e.SetInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0, zmin, zmax);
                     }
                     if (bFoundMMin && bFoundMMax)
                     {
                         e.SetInterval(com.epl.geometry.VertexDescription.Semantics.M, 0, mmin, mmax);
                     }
                     geometry = e;
                 }
             }
         }
         mp = new com.epl.geometry.MapGeometry(geometry, spatial_reference);
     }
     catch (System.Exception)
     {
         return(null);
     }
     return(mp);
 }
 private RasterizedGeometry2DImpl(com.epl.geometry.MultiVertexGeometryImpl geom, double toleranceXY, int rasterSizeBytes)
 {
     Init(geom, toleranceXY, rasterSizeBytes);
 }
 internal static com.epl.geometry.RasterizedGeometry2DImpl CreateImpl(com.epl.geometry.MultiVertexGeometryImpl geom, double toleranceXY, int rasterSizeBytes)
 {
     com.epl.geometry.RasterizedGeometry2DImpl rgImpl = new com.epl.geometry.RasterizedGeometry2DImpl(geom, toleranceXY, rasterSizeBytes);
     return(rgImpl);
 }
        /// <summary>Static method to construct the convex hull of a Multi_vertex_geometry.</summary>
        /// <remarks>
        /// Static method to construct the convex hull of a Multi_vertex_geometry.
        /// Returns a Geometry.
        /// \param mvg The geometry used to create the convex hull.
        /// </remarks>
        internal static com.epl.geometry.Geometry Construct(com.epl.geometry.MultiVertexGeometry mvg)
        {
            if (mvg.IsEmpty())
            {
                return(new com.epl.geometry.Polygon(mvg.GetDescription()));
            }
            com.epl.geometry.MultiVertexGeometryImpl mvg_impl = (com.epl.geometry.MultiVertexGeometryImpl)mvg._getImpl();
            int N = mvg_impl.GetPointCount();

            if (N <= 2)
            {
                if (N == 1 || mvg_impl.GetXY(0).Equals(mvg_impl.GetXY(1)))
                {
                    com.epl.geometry.Point point = new com.epl.geometry.Point(mvg_impl.GetDescription());
                    mvg_impl.GetPointByVal(0, point);
                    return(point);
                }
                else
                {
                    com.epl.geometry.Point    pt       = new com.epl.geometry.Point();
                    com.epl.geometry.Polyline polyline = new com.epl.geometry.Polyline(mvg_impl.GetDescription());
                    mvg_impl.GetPointByVal(0, pt);
                    polyline.StartPath(pt);
                    mvg_impl.GetPointByVal(1, pt);
                    polyline.LineTo(pt);
                    return(polyline);
                }
            }
            com.epl.geometry.AttributeStreamOfDbl stream      = (com.epl.geometry.AttributeStreamOfDbl)mvg_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
            com.epl.geometry.ConvexHull           convex_hull = new com.epl.geometry.ConvexHull(stream, N);
            int t0 = 0;
            int tm = 1;

            com.epl.geometry.Point2D pt_0 = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D pt_m = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D pt_p = new com.epl.geometry.Point2D();
            stream.Read(t0 << 1, pt_0);
            while (true)
            {
                if (tm >= N)
                {
                    break;
                }
                stream.Read(tm << 1, pt_m);
                if (!pt_m.IsEqual(pt_0, com.epl.geometry.NumberUtils.DoubleEps()))
                {
                    break;
                }
                tm++;
            }
            // We don't want to close the gap between t0 and tm.
            convex_hull.m_tree_hull.AddElement(t0, -1);
            if (tm < N)
            {
                convex_hull.m_tree_hull.AddBiggestElement(tm, -1);
                for (int tp = tm + 1; tp < mvg_impl.GetPointCount(); tp++)
                {
                    // Dynamically insert into the current convex hull
                    stream.Read(tp << 1, pt_p);
                    int p = convex_hull.TreeHull_(pt_p);
                    if (p != -1)
                    {
                        convex_hull.m_tree_hull.SetElement(p, tp);
                    }
                }
            }
            // reset the place holder to the point index.
            // Extracts the convex hull from the tree. Reading the tree in order from first to last is the resulting convex hull.
            com.epl.geometry.VertexDescription description = mvg_impl.GetDescription();
            bool b_has_attributes = (description.GetAttributeCount() > 1);
            int  point_count      = convex_hull.m_tree_hull.Size(-1);

            com.epl.geometry.Geometry hull;
            if (point_count >= 2)
            {
                if (point_count >= 3)
                {
                    hull = new com.epl.geometry.Polygon(description);
                }
                else
                {
                    hull = new com.epl.geometry.Polyline(description);
                }
                com.epl.geometry.MultiPathImpl hull_impl = (com.epl.geometry.MultiPathImpl)hull._getImpl();
                hull_impl.AddPath((com.epl.geometry.Point2D[])null, 0, true);
                com.epl.geometry.Point point = null;
                if (b_has_attributes)
                {
                    point = new com.epl.geometry.Point();
                }
                for (int i = convex_hull.m_tree_hull.GetFirst(-1); i != -1; i = convex_hull.m_tree_hull.GetNext(i))
                {
                    if (b_has_attributes)
                    {
                        mvg_impl.GetPointByVal(convex_hull.m_tree_hull.GetElement(i), point);
                        hull_impl.InsertPoint(0, -1, point);
                    }
                    else
                    {
                        stream.Read(convex_hull.m_tree_hull.GetElement(i) << 1, pt_p);
                        hull_impl.InsertPoint(0, -1, pt_p);
                    }
                }
            }
            else
            {
                System.Diagnostics.Debug.Assert((point_count == 1));
                if (b_has_attributes)
                {
                    com.epl.geometry.Point point = new com.epl.geometry.Point(description);
                    mvg_impl.GetPointByVal(convex_hull.m_tree_hull.GetElement(convex_hull.m_tree_hull.GetFirst(-1)), point);
                    hull = point;
                }
                else
                {
                    stream.Read(convex_hull.m_tree_hull.GetElement(convex_hull.m_tree_hull.GetFirst(-1)) << 1, pt_p);
                    hull = new com.epl.geometry.Point(pt_p);
                }
            }
            return(hull);
        }
Example #19
0
 internal override void _copyToImpl(com.epl.geometry.MultiVertexGeometryImpl mvg)
 {
 }