예제 #1
0
 internal override void ApplyTransformation(com.epl.geometry.Transformation3D transform)
 {
     if (IsEmpty())
     {
         return;
     }
     _verifyAllStreams();
     AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
     _verifyAllStreams();
     com.epl.geometry.AttributeStreamOfDbl points = (com.epl.geometry.AttributeStreamOfDbl)m_vertexAttributes[0];
     com.epl.geometry.AttributeStreamOfDbl zs     = (com.epl.geometry.AttributeStreamOfDbl)m_vertexAttributes[1];
     com.epl.geometry.Point3D pt3 = new com.epl.geometry.Point3D();
     for (int ipoint = 0; ipoint < m_pointCount; ipoint++)
     {
         pt3.x = points.Read(ipoint * 2);
         pt3.y = points.Read(ipoint * 2 + 1);
         pt3.z = zs.Read(ipoint);
         com.epl.geometry.Point3D res = transform.Transform(pt3);
         points.Write(ipoint * 2, res.x);
         points.Write(ipoint * 2 + 1, res.y);
         zs.Write(ipoint, res.z);
     }
     // REFACTOR: reset the exact envelope only and transform the loose
     // envelope
     NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyCoordinates);
 }
        // Checked vs. Jan 11, 2011
        internal virtual int QueryCoordinates(com.epl.geometry.Point3D[] dst, int dstSize, int beginIndex, int endIndex)
        {
            int endIndexC = endIndex < 0 ? m_pointCount : endIndex;

            endIndexC = System.Math.Min(endIndexC, beginIndex + dstSize);
            if (beginIndex < 0 || beginIndex >= m_pointCount || endIndexC < beginIndex)
            {
                // TODO replace geometry exc
                throw new System.ArgumentException();
            }
            com.epl.geometry.AttributeStreamOfDbl xy = (com.epl.geometry.AttributeStreamOfDbl)GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
            com.epl.geometry.AttributeStreamOfDbl z  = null;
            double v     = com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.Z);
            bool   bHasZ = HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z);

            if (bHasZ)
            {
                z = (com.epl.geometry.AttributeStreamOfDbl)GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
            }
            int j = 0;

            for (int i = beginIndex; i < endIndexC; i++, j++)
            {
                dst[j].x = xy.Read(2 * i);
                dst[j].y = xy.Read(2 * i + 1);
                dst[j].z = bHasZ ? z.Read(i) : v;
                dst[j]   = GetXYZ(i);
            }
            return(endIndexC);
        }
        internal static com.epl.geometry.Geometry MultiPointSymDiffPoint_(com.epl.geometry.MultiPoint multi_point, com.epl.geometry.Point point, double tolerance, com.epl.geometry.ProgressTracker progress_tracker)
        {
            com.epl.geometry.MultiPointImpl       multipointImpl = (com.epl.geometry.MultiPointImpl)(multi_point._getImpl());
            com.epl.geometry.AttributeStreamOfDbl position       = (com.epl.geometry.AttributeStreamOfDbl)(multipointImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION));
            int point_count = multi_point.GetPointCount();

            com.epl.geometry.Point2D    point2D        = point.GetXY();
            com.epl.geometry.MultiPoint new_multipoint = (com.epl.geometry.MultiPoint)(multi_point.CreateInstance());
            double tolerance_cluster = tolerance * System.Math.Sqrt(2.0) * 1.00001;

            com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D();
            multi_point.QueryEnvelope2D(env);
            env.Inflate(tolerance_cluster, tolerance_cluster);
            if (env.Contains(point2D))
            {
                double tolerance_cluster_sq = tolerance_cluster * tolerance_cluster;
                bool   b_found_covered      = false;
                bool[] covered = new bool[point_count];
                for (int i = 0; i < point_count; i++)
                {
                    covered[i] = false;
                }
                for (int i_1 = 0; i_1 < point_count; i_1++)
                {
                    double x  = position.Read(2 * i_1);
                    double y  = position.Read(2 * i_1 + 1);
                    double dx = x - point2D.x;
                    double dy = y - point2D.y;
                    if (dx * dx + dy * dy <= tolerance_cluster_sq)
                    {
                        b_found_covered = true;
                        covered[i_1]    = true;
                    }
                }
                if (!b_found_covered)
                {
                    new_multipoint.Add(multi_point, 0, point_count);
                    new_multipoint.Add(point);
                }
                else
                {
                    for (int i_2 = 0; i_2 < point_count; i_2++)
                    {
                        if (!covered[i_2])
                        {
                            new_multipoint.Add(multi_point, i_2, i_2 + 1);
                        }
                    }
                }
            }
            else
            {
                new_multipoint.Add(multi_point, 0, point_count);
                new_multipoint.Add(point);
            }
            return(new_multipoint);
        }
예제 #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);
        }
        public override bool Equals(com.epl.geometry.AttributeStreamBase other, int start, int end)
        {
            if (other == null)
            {
                return(false);
            }
            if (!(other is com.epl.geometry.AttributeStreamOfDbl))
            {
                return(false);
            }
            com.epl.geometry.AttributeStreamOfDbl _other = (com.epl.geometry.AttributeStreamOfDbl)other;
            int size      = Size();
            int sizeOther = _other.Size();

            if (end > size || end > sizeOther && (size != sizeOther))
            {
                return(false);
            }
            if (end > size)
            {
                end = size;
            }
            for (int i = start; i < end; i++)
            {
                if (Read(i) != _other.Read(i))
                {
                    return(false);
                }
            }
            return(true);
        }
        private int FindGreatestDistance(com.epl.geometry.Line line, com.epl.geometry.Point2D ptHelper, com.epl.geometry.AttributeStreamOfDbl xy, int start, int end, int pathEnd)
        {
            int to = end - 1;

            if (end <= start)
            {
                // closed path case. end is equal to the path start.
                to = pathEnd;
            }
            int    mid  = -1;
            double maxd = -1.0;

            for (int i = start + 1; i <= to; i++)
            {
                xy.Read(2 * i, ptHelper);
                double x1 = ptHelper.x;
                double y1 = ptHelper.y;
                double t  = line.GetClosestCoordinate(ptHelper, false);
                line.GetCoord2D(t, ptHelper);
                ptHelper.x -= x1;
                ptHelper.y -= y1;
                double dist = ptHelper.Length();
                if (dist > m_maxDeviation && dist > maxd)
                {
                    mid  = i;
                    maxd = dist;
                }
            }
            return(mid);
        }
        internal static void Point_(int precision, bool b_export_zs, bool b_export_ms, com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, int point, System.Text.StringBuilder @string)
        {
            double x = position.Read(2 * point);
            double y = position.Read(2 * point + 1);
            double z = com.epl.geometry.NumberUtils.TheNaN;
            double m = com.epl.geometry.NumberUtils.TheNaN;

            if (b_export_zs)
            {
                z = (zs != null ? zs.Read(point) : com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.Z));
            }
            if (b_export_ms)
            {
                m = (ms != null ? ms.Read(point) : com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.M));
            }
            Point_(precision, b_export_zs, b_export_ms, x, y, z, m, @string);
        }
 // Checked vs. Jan 11, 2011
 /// <summary>\internal Updates x, y intervals.</summary>
 public virtual void _updateXYImpl(bool bExact)
 {
     m_envelope.SetEmpty();
     com.epl.geometry.AttributeStreamOfDbl stream = (com.epl.geometry.AttributeStreamOfDbl)m_vertexAttributes[0];
     com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
     for (int i = 0; i < m_pointCount; i++)
     {
         stream.Read(2 * i, pt);
         m_envelope.Merge(pt);
     }
 }
 internal virtual void CalculateEnvelope2D(com.epl.geometry.Envelope2D env, bool bExact)
 {
     env.SetEmpty();
     com.epl.geometry.AttributeStreamOfDbl stream = (com.epl.geometry.AttributeStreamOfDbl)m_vertexAttributes[0];
     com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
     for (int i = 0; i < m_pointCount; i++)
     {
         stream.Read(2 * i, pt);
         env.Merge(pt);
     }
 }
예제 #10
0
 public override void ApplyTransformation(com.epl.geometry.Transformation2D transform)
 {
     if (IsEmpty())
     {
         return;
     }
     _verifyAllStreams();
     com.epl.geometry.AttributeStreamOfDbl points = (com.epl.geometry.AttributeStreamOfDbl)m_vertexAttributes[0];
     com.epl.geometry.Point2D pt2 = new com.epl.geometry.Point2D();
     for (int ipoint = 0; ipoint < m_pointCount; ipoint++)
     {
         pt2.x = points.Read(ipoint * 2);
         pt2.y = points.Read(ipoint * 2 + 1);
         transform.Transform(pt2, pt2);
         points.Write(ipoint * 2, pt2.x);
         points.Write(ipoint * 2 + 1, pt2.y);
     }
     // REFACTOR: reset the exact envelope only and transform the loose
     // envelope
     NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyCoordinates);
 }
 public override void GetXY(int index, com.epl.geometry.Point2D pt)
 {
     if (index < 0 || index >= GetPointCount())
     {
         throw new System.IndexOutOfRangeException();
     }
     _verifyAllStreams();
     // AttributeStreamOfDbl v = (AttributeStreamOfDbl)
     // m_vertexAttributes[0];
     com.epl.geometry.AttributeStreamOfDbl v = (com.epl.geometry.AttributeStreamOfDbl)m_vertexAttributes[0];
     v.Read(index * 2, pt);
 }
예제 #12
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());
        }
 // Checked vs. Jan 11, 2011
 internal override com.epl.geometry.Point3D GetXYZ(int index)
 {
     if (index < 0 || index >= GetPointCount())
     {
         throw new System.IndexOutOfRangeException();
     }
     _verifyAllStreams();
     com.epl.geometry.AttributeStreamOfDbl v = (com.epl.geometry.AttributeStreamOfDbl)m_vertexAttributes[0];
     com.epl.geometry.Point3D pt             = new com.epl.geometry.Point3D();
     pt.x = v.Read(index * 2);
     pt.y = v.Read(index * 2 + 1);
     // TODO check excluded if statement componenet
     if (HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z))
     {
         // && (m_vertexAttributes[1] != null))
         pt.z = m_vertexAttributes[1].ReadAsDbl(index);
     }
     else
     {
         pt.z = com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.Z);
     }
     return(pt);
 }
예제 #14
0
        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++;
            }
        }
        public override void ReplaceNaNs(int semantics, double value)
        {
            AddAttribute(semantics);
            if (IsEmpty())
            {
                return;
            }
            bool modified = false;
            int  ncomps   = com.epl.geometry.VertexDescription.GetComponentCount(semantics);

            for (int i = 0; i < ncomps; i++)
            {
                com.epl.geometry.AttributeStreamBase streamBase = GetAttributeStreamRef(semantics);
                if (streamBase is com.epl.geometry.AttributeStreamOfDbl)
                {
                    com.epl.geometry.AttributeStreamOfDbl dblStream = (com.epl.geometry.AttributeStreamOfDbl)streamBase;
                    for (int ivert = 0, n = m_pointCount * ncomps; ivert < n; ivert++)
                    {
                        double v = dblStream.Read(ivert);
                        if (double.IsNaN(v))
                        {
                            dblStream.Write(ivert, value);
                            modified = true;
                        }
                    }
                }
                else
                {
                    for (int ivert = 0, n = m_pointCount * ncomps; ivert < n; ivert++)
                    {
                        double v = streamBase.ReadAsDbl(ivert);
                        if (double.IsNaN(v))
                        {
                            streamBase.WriteAsDbl(ivert, value);
                            modified = true;
                        }
                    }
                }
            }
            if (modified)
            {
                NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyCoordinates);
            }
        }
        internal static com.epl.geometry.Geometry MultiPointMinusPoint_(com.epl.geometry.MultiPoint multi_point, com.epl.geometry.Point point, double tolerance, com.epl.geometry.ProgressTracker progress_tracker)
        {
            com.epl.geometry.MultiPointImpl       multipointImpl = (com.epl.geometry.MultiPointImpl)(multi_point._getImpl());
            com.epl.geometry.AttributeStreamOfDbl position       = (com.epl.geometry.AttributeStreamOfDbl)(multipointImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION));
            int point_count = multi_point.GetPointCount();

            com.epl.geometry.Point2D point2D = point.GetXY();
            com.epl.geometry.Point2D pt      = new com.epl.geometry.Point2D();
            bool b_found_covered             = false;

            bool[] covered = new bool[point_count];
            for (int i = 0; i < point_count; i++)
            {
                covered[i] = false;
            }
            double tolerance_cluster    = tolerance * System.Math.Sqrt(2.0) * 1.00001;
            double tolerance_cluster_sq = tolerance_cluster * tolerance_cluster;

            for (int i_1 = 0; i_1 < point_count; i_1++)
            {
                position.Read(2 * i_1, pt);
                double sqr_dist = com.epl.geometry.Point2D.SqrDistance(pt, point2D);
                if (sqr_dist <= tolerance_cluster_sq)
                {
                    b_found_covered = true;
                    covered[i_1]    = true;
                }
            }
            if (!b_found_covered)
            {
                return(multi_point);
            }
            com.epl.geometry.MultiPoint new_multipoint = (com.epl.geometry.MultiPoint)(multi_point.CreateInstance());
            for (int i_2 = 0; i_2 < point_count; i_2++)
            {
                if (!covered[i_2])
                {
                    new_multipoint.Add(multi_point, i_2, i_2 + 1);
                }
            }
            return(new_multipoint);
        }
        internal static com.epl.geometry.Geometry PointMinusMultiPoint_(com.epl.geometry.Point point, com.epl.geometry.MultiPoint multi_point, double tolerance, com.epl.geometry.ProgressTracker progress_tracker)
        {
            com.epl.geometry.MultiPointImpl       multipointImpl = (com.epl.geometry.MultiPointImpl)(multi_point._getImpl());
            com.epl.geometry.AttributeStreamOfDbl position       = (com.epl.geometry.AttributeStreamOfDbl)multipointImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
            int point_count = multi_point.GetPointCount();

            com.epl.geometry.Point2D point2D = point.GetXY();
            com.epl.geometry.Point2D pt      = new com.epl.geometry.Point2D();
            double tolerance_cluster         = tolerance * System.Math.Sqrt(2.0) * 1.00001;
            double tolerance_cluster_sq      = tolerance_cluster * tolerance_cluster;

            for (int i = 0; i < point_count; i++)
            {
                position.Read(2 * i, pt);
                double sqr_dist = com.epl.geometry.Point2D.SqrDistance(pt, point2D);
                if (sqr_dist <= tolerance_cluster_sq)
                {
                    return(point.CreateInstance());
                }
            }
            // return an empty point.
            return(point);
        }
        public static void CompareGeometryContent(com.epl.geometry.MultiVertexGeometry geom1, com.epl.geometry.MultiVertexGeometry geom2)
        {
            // Geometry types
            NUnit.Framework.Assert.IsTrue(geom1.GetType().Value() == geom2.GetType().Value());
            // Envelopes
            com.epl.geometry.Envelope2D env1 = new com.epl.geometry.Envelope2D();
            geom1.QueryEnvelope2D(env1);
            com.epl.geometry.Envelope2D env2 = new com.epl.geometry.Envelope2D();
            geom2.QueryEnvelope2D(env2);
            NUnit.Framework.Assert.IsTrue(env1.xmin == env2.xmin && env1.xmax == env2.xmax && env1.ymin == env2.ymin && env1.ymax == env2.ymax);
            int type = geom1.GetType().Value();

            if (type == com.epl.geometry.Geometry.GeometryType.Polyline || type == com.epl.geometry.Geometry.GeometryType.Polygon)
            {
                // Part Count
                int partCount1 = ((com.epl.geometry.MultiPath)geom1).GetPathCount();
                int partCount2 = ((com.epl.geometry.MultiPath)geom2).GetPathCount();
                NUnit.Framework.Assert.IsTrue(partCount1 == partCount2);
                // Part indices
                for (int i = 0; i < partCount1; i++)
                {
                    int start1 = ((com.epl.geometry.MultiPath)geom1).GetPathStart(i);
                    int start2 = ((com.epl.geometry.MultiPath)geom2).GetPathStart(i);
                    NUnit.Framework.Assert.IsTrue(start1 == start2);
                    int end1 = ((com.epl.geometry.MultiPath)geom1).GetPathEnd(i);
                    int end2 = ((com.epl.geometry.MultiPath)geom2).GetPathEnd(i);
                    NUnit.Framework.Assert.IsTrue(end1 == end2);
                }
            }
            // Point count
            int pointCount1 = geom1.GetPointCount();
            int pointCount2 = geom2.GetPointCount();

            NUnit.Framework.Assert.IsTrue(pointCount1 == pointCount2);
            if (type == com.epl.geometry.Geometry.GeometryType.MultiPoint || type == com.epl.geometry.Geometry.GeometryType.Polyline || type == com.epl.geometry.Geometry.GeometryType.Polygon)
            {
                // POSITION
                com.epl.geometry.AttributeStreamBase  positionStream1 = ((com.epl.geometry.MultiVertexGeometryImpl)geom1._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
                com.epl.geometry.AttributeStreamOfDbl position1       = (com.epl.geometry.AttributeStreamOfDbl)(positionStream1);
                com.epl.geometry.AttributeStreamBase  positionStream2 = ((com.epl.geometry.MultiVertexGeometryImpl)geom2._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
                com.epl.geometry.AttributeStreamOfDbl position2       = (com.epl.geometry.AttributeStreamOfDbl)(positionStream2);
                for (int i = 0; i < pointCount1; i++)
                {
                    double x1 = position1.Read(2 * i);
                    double x2 = position2.Read(2 * i);
                    NUnit.Framework.Assert.IsTrue(x1 == x2);
                    double y1 = position1.Read(2 * i + 1);
                    double y2 = position2.Read(2 * i + 1);
                    NUnit.Framework.Assert.IsTrue(y1 == y2);
                }
                // Zs
                bool bHasZs1 = geom1.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                bool bHasZs2 = geom2.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                NUnit.Framework.Assert.IsTrue(bHasZs1 == bHasZs2);
                if (bHasZs1)
                {
                    com.epl.geometry.AttributeStreamBase  zStream1 = ((com.epl.geometry.MultiVertexGeometryImpl)geom1._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
                    com.epl.geometry.AttributeStreamOfDbl zs1      = (com.epl.geometry.AttributeStreamOfDbl)(zStream1);
                    com.epl.geometry.AttributeStreamBase  zStream2 = ((com.epl.geometry.MultiVertexGeometryImpl)geom2._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
                    com.epl.geometry.AttributeStreamOfDbl zs2      = (com.epl.geometry.AttributeStreamOfDbl)(zStream2);
                    for (int i_1 = 0; i_1 < pointCount1; i_1++)
                    {
                        double z1 = zs1.Read(i_1);
                        double z2 = zs2.Read(i_1);
                        NUnit.Framework.Assert.IsTrue(z1 == z2);
                    }
                }
                // Ms
                bool bHasMs1 = geom1.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                bool bHasMs2 = geom2.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                NUnit.Framework.Assert.IsTrue(bHasMs1 == bHasMs2);
                if (bHasMs1)
                {
                    com.epl.geometry.AttributeStreamBase  mStream1 = ((com.epl.geometry.MultiVertexGeometryImpl)geom1._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M);
                    com.epl.geometry.AttributeStreamOfDbl ms1      = (com.epl.geometry.AttributeStreamOfDbl)(mStream1);
                    com.epl.geometry.AttributeStreamBase  mStream2 = ((com.epl.geometry.MultiVertexGeometryImpl)geom2._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M);
                    com.epl.geometry.AttributeStreamOfDbl ms2      = (com.epl.geometry.AttributeStreamOfDbl)(mStream2);
                    for (int i_1 = 0; i_1 < pointCount1; i_1++)
                    {
                        double m1 = ms1.Read(i_1);
                        double m2 = ms2.Read(i_1);
                        NUnit.Framework.Assert.IsTrue(m1 == m2);
                    }
                }
                // IDs
                bool bHasIDs1 = geom1.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID);
                bool bHasIDs2 = geom2.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID);
                NUnit.Framework.Assert.IsTrue(bHasIDs1 == bHasIDs2);
                if (bHasIDs1)
                {
                    com.epl.geometry.AttributeStreamBase    idStream1 = ((com.epl.geometry.MultiVertexGeometryImpl)geom1._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.ID);
                    com.epl.geometry.AttributeStreamOfInt32 ids1      = (com.epl.geometry.AttributeStreamOfInt32)(idStream1);
                    com.epl.geometry.AttributeStreamBase    idStream2 = ((com.epl.geometry.MultiVertexGeometryImpl)geom2._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.ID);
                    com.epl.geometry.AttributeStreamOfInt32 ids2      = (com.epl.geometry.AttributeStreamOfInt32)(idStream2);
                    for (int i_1 = 0; i_1 < pointCount1; i_1++)
                    {
                        int id1 = ids1.Read(i_1);
                        int id2 = ids2.Read(i_1);
                        NUnit.Framework.Assert.IsTrue(id1 == id2);
                    }
                }
            }
        }
예제 #19
0
        /// <summary>Returns true if the given path of the input MultiPath is convex.</summary>
        /// <remarks>
        /// Returns true if the given path of the input MultiPath is convex. Returns false otherwise.
        /// \param multi_path The MultiPath to check if the path is convex.
        /// \param path_index The path of the MultiPath to check if its convex.
        /// </remarks>
        internal static bool IsPathConvex(com.epl.geometry.MultiPath multi_path, int path_index, com.epl.geometry.ProgressTracker progress_tracker)
        {
            com.epl.geometry.MultiPathImpl mimpl = (com.epl.geometry.MultiPathImpl)multi_path._getImpl();
            int  path_start = mimpl.GetPathStart(path_index);
            int  path_end   = mimpl.GetPathEnd(path_index);
            bool bxyclosed  = !mimpl.IsClosedPath(path_index) && mimpl.IsClosedPathInXYPlane(path_index);

            com.epl.geometry.AttributeStreamOfDbl position = (com.epl.geometry.AttributeStreamOfDbl)(mimpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION));
            int position_start = 2 * path_start;
            int position_end   = 2 * path_end;

            if (bxyclosed)
            {
                position_end -= 2;
            }
            if (position_end - position_start < 6)
            {
                return(true);
            }
            // This matches the logic for case 1 of the tree hull algorithm. The idea is inductive. We assume we have a convex hull pt_0,...,pt_m, and we see if
            // a new point (pt_pivot) is among the transitive tournament for pt_0, knowing that pt_pivot comes after pt_m.
            // We check three conditions:
            // 1) pt_m->pt_pivot->pt_0 is clockwise (closure across the boundary is convex)
            // 2) pt_1->pt_pivot->pt_0 is clockwise (the first step forward is convex)  (pt_1 is the next point after pt_0)
            // 3) pt_m->pt_pivot->pt_m_prev is clockwise (the first step backwards is convex)  (pt_m_prev is the previous point before pt_m)
            // If all three of the above conditions are clockwise, then pt_pivot is among the transitive tournament for pt_0, and therefore the polygon pt_0, ..., pt_m, pt_pivot is convex.
            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_pivot = new com.epl.geometry.Point2D();
            position.Read(position_start, pt_0);
            position.Read(position_start + 2, pt_m);
            position.Read(position_start + 4, pt_pivot);
            // Initial inductive step
            com.epl.geometry.ECoordinate det_ec = Determinant_(pt_m, pt_pivot, pt_0);
            if (det_ec.IsFuzzyZero() || !IsClockwise_(det_ec.Value()))
            {
                return(false);
            }
            com.epl.geometry.Point2D pt_1      = new com.epl.geometry.Point2D(pt_m.x, pt_m.y);
            com.epl.geometry.Point2D pt_m_prev = new com.epl.geometry.Point2D();
            // Assume that pt_0,...,pt_m is convex. Check if the next point, pt_pivot, maintains the convex invariant.
            for (int i = position_start + 6; i < position_end; i += 2)
            {
                pt_m_prev.SetCoords(pt_m);
                pt_m.SetCoords(pt_pivot);
                position.Read(i, pt_pivot);
                det_ec = Determinant_(pt_m, pt_pivot, pt_0);
                if (det_ec.IsFuzzyZero() || !IsClockwise_(det_ec.Value()))
                {
                    return(false);
                }
                det_ec = Determinant_(pt_1, pt_pivot, pt_0);
                if (det_ec.IsFuzzyZero() || !IsClockwise_(det_ec.Value()))
                {
                    return(false);
                }
                det_ec = Determinant_(pt_m, pt_pivot, pt_m_prev);
                if (det_ec.IsFuzzyZero() || !IsClockwise_(det_ec.Value()))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #20
0
        /// <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);
        }
        private static int ExportMultiPathToESRIShape(bool bPolygon, int exportFlags, com.epl.geometry.MultiPath multipath, System.IO.BinaryWriter shapeBuffer)
        {
            com.epl.geometry.MultiPathImpl multipathImpl = (com.epl.geometry.MultiPathImpl)multipath._getImpl();
            bool bExportZs    = multipathImpl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripZs) == 0;
            bool bExportMs    = multipathImpl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripMs) == 0;
            bool bExportIDs   = multipathImpl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripIDs) == 0;
            bool bHasCurves   = multipathImpl.HasNonLinearSegments();
            bool bArcViewNaNs = (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportTrueNaNs) == 0;
            int  partCount    = multipathImpl.GetPathCount();
            int  pointCount   = multipathImpl.GetPointCount();

            if (!bPolygon)
            {
                for (int ipart = 0; ipart < partCount; ipart++)
                {
                    if (multipath.IsClosedPath(ipart))
                    {
                        pointCount++;
                    }
                }
            }
            else
            {
                pointCount += partCount;
            }
            int size = (4) + (4 * 8) + (4) + (4) + (partCount * 4) + pointCount * 2 * 8;

            /* type */
            /* envelope */
            /* part count */
            /* point count */
            /* start indices */
            /* xy coordinates */
            if (bExportZs)
            {
                size += (2 * 8) + (pointCount * 8);
            }
            /* min max */
            /* zs */
            if (bExportMs)
            {
                size += (2 * 8) + (pointCount * 8);
            }
            /* min max */
            /* ms */
            if (bExportIDs)
            {
                size += pointCount * 4;
            }
            /* ids */
            if (bHasCurves)
            {
            }
            // to-do: curves
            if (size >= com.epl.geometry.NumberUtils.IntMax())
            {
                throw new com.epl.geometry.GeometryException("invalid call");
            }
            if (shapeBuffer == null)
            {
                return(size);
            }
            else
            {
                if (((System.IO.MemoryStream)shapeBuffer.BaseStream).Capacity < size)
                {
                    throw new com.epl.geometry.GeometryException("buffer is too small");
                }
            }
            int offset = 0;
            // Determine the shape type
            int type;

            if (!bExportZs && !bExportMs)
            {
                if (bExportIDs || bHasCurves)
                {
                    type = bPolygon ? com.epl.geometry.ShapeType.ShapeGeneralPolygon : com.epl.geometry.ShapeType.ShapeGeneralPolyline;
                    if (bExportIDs)
                    {
                        type |= com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                    }
                    if (bHasCurves)
                    {
                        type |= com.epl.geometry.ShapeModifiers.ShapeHasCurves;
                    }
                }
                else
                {
                    type = bPolygon ? com.epl.geometry.ShapeType.ShapePolygon : com.epl.geometry.ShapeType.ShapePolyline;
                }
            }
            else
            {
                if (bExportZs && !bExportMs)
                {
                    if (bExportIDs || bHasCurves)
                    {
                        type  = bPolygon ? com.epl.geometry.ShapeType.ShapeGeneralPolygon : com.epl.geometry.ShapeType.ShapeGeneralPolyline;
                        type |= com.epl.geometry.ShapeModifiers.ShapeHasZs;
                        if (bExportIDs)
                        {
                            type |= com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                        }
                        if (bHasCurves)
                        {
                            type |= com.epl.geometry.ShapeModifiers.ShapeHasCurves;
                        }
                    }
                    else
                    {
                        type = bPolygon ? com.epl.geometry.ShapeType.ShapePolygonZ : com.epl.geometry.ShapeType.ShapePolylineZ;
                    }
                }
                else
                {
                    if (bExportMs && !bExportZs)
                    {
                        if (bExportIDs || bHasCurves)
                        {
                            type  = bPolygon ? com.epl.geometry.ShapeType.ShapeGeneralPolygon : com.epl.geometry.ShapeType.ShapeGeneralPolyline;
                            type |= com.epl.geometry.ShapeModifiers.ShapeHasMs;
                            if (bExportIDs)
                            {
                                type |= com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                            }
                            if (bHasCurves)
                            {
                                type |= com.epl.geometry.ShapeModifiers.ShapeHasCurves;
                            }
                        }
                        else
                        {
                            type = bPolygon ? com.epl.geometry.ShapeType.ShapePolygonM : com.epl.geometry.ShapeType.ShapePolylineM;
                        }
                    }
                    else
                    {
                        if (bExportIDs || bHasCurves)
                        {
                            type  = bPolygon ? com.epl.geometry.ShapeType.ShapeGeneralPolygon : com.epl.geometry.ShapeType.ShapeGeneralPolyline;
                            type |= com.epl.geometry.ShapeModifiers.ShapeHasZs | com.epl.geometry.ShapeModifiers.ShapeHasMs;
                            if (bExportIDs)
                            {
                                type |= com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                            }
                            if (bHasCurves)
                            {
                                type |= com.epl.geometry.ShapeModifiers.ShapeHasCurves;
                            }
                        }
                        else
                        {
                            type = bPolygon ? com.epl.geometry.ShapeType.ShapePolygonZM : com.epl.geometry.ShapeType.ShapePolylineZM;
                        }
                    }
                }
            }
            // write type
            shapeBuffer.Write(type);
            offset += 4;
            // write Envelope
            com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D();
            multipathImpl.QueryEnvelope2D(env);
            // calls _VerifyAllStreams
            shapeBuffer.Write(env.xmin);
            offset += 8;
            shapeBuffer.Write(env.ymin);
            offset += 8;
            shapeBuffer.Write(env.xmax);
            offset += 8;
            shapeBuffer.Write(env.ymax);
            offset += 8;
            // write part count
            shapeBuffer.Write(partCount);
            offset += 4;
            // to-do: return error if larger than 2^32 - 1
            // write pointCount
            shapeBuffer.Write(pointCount);
            offset += 4;
            // write start indices for each part
            int pointIndexDelta = 0;

            for (int ipart = 0; ipart < partCount; ipart++)
            {
                int istart = multipathImpl.GetPathStart(ipart) + pointIndexDelta;
                shapeBuffer.Write(istart);
                offset += 4;
                if (bPolygon || multipathImpl.IsClosedPath(ipart))
                {
                    pointIndexDelta++;
                }
            }
            if (pointCount > 0)
            {
                // write xy coordinates
                com.epl.geometry.AttributeStreamBase  positionStream = multipathImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
                com.epl.geometry.AttributeStreamOfDbl position       = (com.epl.geometry.AttributeStreamOfDbl)positionStream;
                for (int ipart = 0; ipart < partCount; ipart++)
                {
                    int partStart = multipathImpl.GetPathStart(ipart);
                    int partEnd   = multipathImpl.GetPathEnd(ipart);
                    for (int i = partStart; i < partEnd; i++)
                    {
                        double x = position.Read(2 * i);
                        double y = position.Read(2 * i + 1);
                        shapeBuffer.Write(x);
                        offset += 8;
                        shapeBuffer.Write(y);
                        offset += 8;
                    }
                    // If the part is closed, then we need to duplicate the start
                    // point
                    if (bPolygon || multipathImpl.IsClosedPath(ipart))
                    {
                        double x = position.Read(2 * partStart);
                        double y = position.Read(2 * partStart + 1);
                        shapeBuffer.Write(x);
                        offset += 8;
                        shapeBuffer.Write(y);
                        offset += 8;
                    }
                }
            }
            // write Zs
            if (bExportZs)
            {
                com.epl.geometry.Envelope1D zInterval = multipathImpl.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0);
                shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(zInterval.vmin) : zInterval.vmin);
                offset += 8;
                shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(zInterval.vmax) : zInterval.vmax);
                offset += 8;
                if (pointCount > 0)
                {
                    if (multipathImpl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z))
                    {
                        com.epl.geometry.AttributeStreamOfDbl zs = (com.epl.geometry.AttributeStreamOfDbl)multipathImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
                        for (int ipart = 0; ipart < partCount; ipart++)
                        {
                            int partStart = multipathImpl.GetPathStart(ipart);
                            int partEnd   = multipathImpl.GetPathEnd(ipart);
                            for (int i = partStart; i < partEnd; i++)
                            {
                                double z = zs.Read(i);
                                shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(z) : z);
                                offset += 8;
                            }
                            // If the part is closed, then we need to duplicate the
                            // start z
                            if (bPolygon || multipathImpl.IsClosedPath(ipart))
                            {
                                double z = zs.Read(partStart);
                                shapeBuffer.Write(z);
                                offset += 8;
                            }
                        }
                    }
                    else
                    {
                        double z = com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.Z);
                        if (bArcViewNaNs)
                        {
                            z = com.epl.geometry.Interop.TranslateToAVNaN(z);
                        }
                        for (int i = 0; i < pointCount; i++)
                        {
                            shapeBuffer.Write(z);
                        }
                        offset += 8;
                    }
                }
            }
            // write Ms
            if (bExportMs)
            {
                com.epl.geometry.Envelope1D mInterval = multipathImpl.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0);
                shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(mInterval.vmin) : mInterval.vmin);
                offset += 8;
                shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(mInterval.vmax) : mInterval.vmax);
                offset += 8;
                if (pointCount > 0)
                {
                    if (multipathImpl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M))
                    {
                        com.epl.geometry.AttributeStreamOfDbl ms = (com.epl.geometry.AttributeStreamOfDbl)multipathImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M);
                        for (int ipart = 0; ipart < partCount; ipart++)
                        {
                            int partStart = multipathImpl.GetPathStart(ipart);
                            int partEnd   = multipathImpl.GetPathEnd(ipart);
                            for (int i = partStart; i < partEnd; i++)
                            {
                                double m = ms.Read(i);
                                shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(m) : m);
                                offset += 8;
                            }
                            // If the part is closed, then we need to duplicate the
                            // start m
                            if (bPolygon || multipathImpl.IsClosedPath(ipart))
                            {
                                double m = ms.Read(partStart);
                                shapeBuffer.Write(m);
                                offset += 8;
                            }
                        }
                    }
                    else
                    {
                        double m = com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.M);
                        if (bArcViewNaNs)
                        {
                            m = com.epl.geometry.Interop.TranslateToAVNaN(m);
                        }
                        for (int i = 0; i < pointCount; i++)
                        {
                            shapeBuffer.Write(m);
                        }
                        offset += 8;
                    }
                }
            }
            // write Curves
            if (bHasCurves)
            {
            }
            // to-do: We'll finish this later
            // write IDs
            if (bExportIDs)
            {
                if (pointCount > 0)
                {
                    if (multipathImpl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.ID))
                    {
                        com.epl.geometry.AttributeStreamOfInt32 ids = (com.epl.geometry.AttributeStreamOfInt32)multipathImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.ID);
                        for (int ipart = 0; ipart < partCount; ipart++)
                        {
                            int partStart = multipathImpl.GetPathStart(ipart);
                            int partEnd   = multipathImpl.GetPathEnd(ipart);
                            for (int i = partStart; i < partEnd; i++)
                            {
                                int id = ids.Read(i);
                                shapeBuffer.Write(id);
                                offset += 4;
                            }
                            // If the part is closed, then we need to duplicate the
                            // start id
                            if (bPolygon || multipathImpl.IsClosedPath(ipart))
                            {
                                int id = ids.Read(partStart);
                                shapeBuffer.Write(id);
                                offset += 4;
                            }
                        }
                    }
                    else
                    {
                        int id = (int)com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.ID);
                        for (int i = 0; i < pointCount; i++)
                        {
                            shapeBuffer.Write(id);
                        }
                        offset += 4;
                    }
                }
            }
            return(offset);
        }
        private static int ExportMultiPointToESRIShape(int exportFlags, com.epl.geometry.MultiPoint multipoint, System.IO.BinaryWriter shapeBuffer)
        {
            com.epl.geometry.MultiPointImpl multipointImpl = (com.epl.geometry.MultiPointImpl)multipoint._getImpl();
            bool bExportZs    = multipointImpl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripZs) == 0;
            bool bExportMs    = multipointImpl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripMs) == 0;
            bool bExportIDs   = multipointImpl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripIDs) == 0;
            bool bArcViewNaNs = (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportTrueNaNs) == 0;
            int  pointCount   = multipointImpl.GetPointCount();
            int  size         = (4) + (4 * 8) + (4) + (pointCount * 2 * 8);

            /* type */
            /* envelope */
            /* point count */
            /* xy coordinates */
            if (bExportZs)
            {
                size += (2 * 8) + (pointCount * 8);
            }
            /* min max */
            /* zs */
            if (bExportMs)
            {
                size += (2 * 8) + (pointCount * 8);
            }
            /* min max */
            /* ms */
            if (bExportIDs)
            {
                size += pointCount * 4;
            }
            /* ids */
            if (size >= com.epl.geometry.NumberUtils.IntMax())
            {
                throw new com.epl.geometry.GeometryException("invalid call");
            }
            if (shapeBuffer == null)
            {
                return(size);
            }
            else
            {
                if (((System.IO.MemoryStream)shapeBuffer.BaseStream).Capacity < size)
                {
                    throw new com.epl.geometry.GeometryException("buffer is too small");
                }
            }
            int type;

            // Determine the shape type
            if (!bExportZs && !bExportMs)
            {
                if (bExportIDs)
                {
                    type = com.epl.geometry.ShapeType.ShapeGeneralMultiPoint | com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                }
                else
                {
                    type = com.epl.geometry.ShapeType.ShapeMultiPoint;
                }
            }
            else
            {
                if (bExportZs && !bExportMs)
                {
                    if (bExportIDs)
                    {
                        type = com.epl.geometry.ShapeType.ShapeGeneralMultiPoint | com.epl.geometry.ShapeModifiers.ShapeHasZs | com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                    }
                    else
                    {
                        type = com.epl.geometry.ShapeType.ShapeMultiPointZ;
                    }
                }
                else
                {
                    if (bExportMs && !bExportZs)
                    {
                        if (bExportIDs)
                        {
                            type = com.epl.geometry.ShapeType.ShapeGeneralMultiPoint | com.epl.geometry.ShapeModifiers.ShapeHasMs | com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                        }
                        else
                        {
                            type = com.epl.geometry.ShapeType.ShapeMultiPointM;
                        }
                    }
                    else
                    {
                        if (bExportIDs)
                        {
                            type = com.epl.geometry.ShapeType.ShapeGeneralMultiPoint | com.epl.geometry.ShapeModifiers.ShapeHasZs | com.epl.geometry.ShapeModifiers.ShapeHasMs | com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                        }
                        else
                        {
                            type = com.epl.geometry.ShapeType.ShapeMultiPointZM;
                        }
                    }
                }
            }
            // write type
            int offset = 0;

            shapeBuffer.Write(type);
            offset += 4;
            // write Envelope
            com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D();
            multipointImpl.QueryEnvelope2D(env);
            // calls _VerifyAllStreams
            shapeBuffer.Write(env.xmin);
            offset += 8;
            shapeBuffer.Write(env.ymin);
            offset += 8;
            shapeBuffer.Write(env.xmax);
            offset += 8;
            shapeBuffer.Write(env.ymax);
            offset += 8;
            // write point count
            shapeBuffer.Write(pointCount);
            offset += 4;
            if (pointCount > 0)
            {
                // write xy coordinates
                com.epl.geometry.AttributeStreamBase  positionStream = multipointImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
                com.epl.geometry.AttributeStreamOfDbl position       = (com.epl.geometry.AttributeStreamOfDbl)positionStream;
                for (int i = 0; i < pointCount; i++)
                {
                    double x = position.Read(2 * i);
                    double y = position.Read(2 * i + 1);
                    shapeBuffer.Write(x);
                    offset += 8;
                    shapeBuffer.Write(y);
                    offset += 8;
                }
            }
            // write Zs
            if (bExportZs)
            {
                com.epl.geometry.Envelope1D zInterval = multipointImpl.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0);
                shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(zInterval.vmin) : zInterval.vmin);
                offset += 8;
                shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(zInterval.vmax) : zInterval.vmax);
                offset += 8;
                if (pointCount > 0)
                {
                    if (multipointImpl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z))
                    {
                        com.epl.geometry.AttributeStreamOfDbl zs = (com.epl.geometry.AttributeStreamOfDbl)multipointImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
                        for (int i = 0; i < pointCount; i++)
                        {
                            double z = zs.Read(i);
                            shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(z) : z);
                            offset += 8;
                        }
                    }
                    else
                    {
                        double z = com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.Z);
                        if (bArcViewNaNs)
                        {
                            z = com.epl.geometry.Interop.TranslateToAVNaN(z);
                        }
                        // Can we write a function that writes all these values at
                        // once instead of doing a for loop?
                        for (int i = 0; i < pointCount; i++)
                        {
                            shapeBuffer.Write(z);
                        }
                        offset += 8;
                    }
                }
            }
            // write Ms
            if (bExportMs)
            {
                com.epl.geometry.Envelope1D mInterval = multipointImpl.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0);
                shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(mInterval.vmin) : mInterval.vmin);
                offset += 8;
                shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(mInterval.vmax) : mInterval.vmax);
                offset += 8;
                if (pointCount > 0)
                {
                    if (multipointImpl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M))
                    {
                        com.epl.geometry.AttributeStreamOfDbl ms = (com.epl.geometry.AttributeStreamOfDbl)multipointImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M);
                        for (int i = 0; i < pointCount; i++)
                        {
                            double m = ms.Read(i);
                            shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(m) : m);
                            offset += 8;
                        }
                    }
                    else
                    {
                        double m = com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.M);
                        if (bArcViewNaNs)
                        {
                            m = com.epl.geometry.Interop.TranslateToAVNaN(m);
                        }
                        for (int i = 0; i < pointCount; i++)
                        {
                            shapeBuffer.Write(m);
                        }
                        offset += 8;
                    }
                }
            }
            // write IDs
            if (bExportIDs)
            {
                if (pointCount > 0)
                {
                    if (multipointImpl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.ID))
                    {
                        com.epl.geometry.AttributeStreamOfInt32 ids = (com.epl.geometry.AttributeStreamOfInt32)multipointImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.ID);
                        for (int i = 0; i < pointCount; i++)
                        {
                            int id = ids.Read(i);
                            shapeBuffer.Write(id);
                            offset += 4;
                        }
                    }
                    else
                    {
                        int id = (int)com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.ID);
                        for (int i = 0; i < pointCount; i++)
                        {
                            shapeBuffer.Write(id);
                        }
                        offset += 4;
                    }
                }
            }
            return(offset);
        }
예제 #23
0
 public override int Compare(int v1, int v2)
 {
     m_xy.Read(2 * v1, pt1_helper);
     m_xy.Read(2 * v2, pt2_helper);
     return(pt1_helper.Compare(pt2_helper));
 }
예제 #24
0
 public override double GetValue(int index)
 {
     return(m_xy.Read(2 * index + 1));
 }
예제 #25
0
 internal static com.epl.geometry.MultiPoint CalculatePolylineBoundary_(object impl, com.epl.geometry.ProgressTracker progress_tracker, bool only_check_non_empty_boundary, bool[] not_empty)
 {
     if (not_empty != null)
     {
         not_empty[0] = false;
     }
     com.epl.geometry.MultiPathImpl mpImpl = (com.epl.geometry.MultiPathImpl)impl;
     com.epl.geometry.MultiPoint    dst    = null;
     if (!only_check_non_empty_boundary)
     {
         dst = new com.epl.geometry.MultiPoint(mpImpl.GetDescription());
     }
     if (!mpImpl.IsEmpty())
     {
         com.epl.geometry.AttributeStreamOfInt32 indices = new com.epl.geometry.AttributeStreamOfInt32(0);
         indices.Reserve(mpImpl.GetPathCount() * 2);
         for (int ipath = 0, nPathCount = mpImpl.GetPathCount(); ipath < nPathCount; ipath++)
         {
             int path_size = mpImpl.GetPathSize(ipath);
             if (path_size > 0 && !mpImpl.IsClosedPathInXYPlane(ipath))
             {
                 // closed
                 // paths
                 // of
                 // polyline
                 // do
                 // not
                 // contribute
                 // to
                 // the
                 // boundary.
                 int start = mpImpl.GetPathStart(ipath);
                 indices.Add(start);
                 int end = mpImpl.GetPathEnd(ipath) - 1;
                 indices.Add(end);
             }
         }
         if (indices.Size() > 0)
         {
             com.epl.geometry.BucketSort           sorter = new com.epl.geometry.BucketSort();
             com.epl.geometry.AttributeStreamOfDbl xy     = (com.epl.geometry.AttributeStreamOfDbl)(mpImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION));
             sorter.Sort(indices, 0, indices.Size(), new com.epl.geometry.Boundary.MultiPathImplBoundarySorter(xy));
             com.epl.geometry.Point2D ptPrev = new com.epl.geometry.Point2D();
             xy.Read(2 * indices.Get(0), ptPrev);
             int ind     = 0;
             int counter = 1;
             com.epl.geometry.Point   point = new com.epl.geometry.Point();
             com.epl.geometry.Point2D pt    = new com.epl.geometry.Point2D();
             for (int i = 1, n = indices.Size(); i < n; i++)
             {
                 xy.Read(2 * indices.Get(i), pt);
                 if (pt.IsEqual(ptPrev))
                 {
                     if (indices.Get(ind) > indices.Get(i))
                     {
                         // remove duplicate point
                         indices.Set(ind, com.epl.geometry.NumberUtils.IntMax());
                         ind = i;
                     }
                     else
                     {
                         // just for the heck of it, have the first
                         // point in the order to be added to the
                         // boundary.
                         indices.Set(i, com.epl.geometry.NumberUtils.IntMax());
                     }
                     counter++;
                 }
                 else
                 {
                     if ((counter & 1) == 0)
                     {
                         // remove boundary point
                         indices.Set(ind, com.epl.geometry.NumberUtils.IntMax());
                     }
                     else
                     {
                         if (only_check_non_empty_boundary)
                         {
                             if (not_empty != null)
                             {
                                 not_empty[0] = true;
                             }
                             return(null);
                         }
                     }
                     ptPrev.SetCoords(pt);
                     ind     = i;
                     counter = 1;
                 }
             }
             if ((counter & 1) == 0)
             {
                 // remove the point
                 indices.Set(ind, com.epl.geometry.NumberUtils.IntMax());
             }
             else
             {
                 if (only_check_non_empty_boundary)
                 {
                     if (not_empty != null)
                     {
                         not_empty[0] = true;
                     }
                     return(null);
                 }
             }
             if (!only_check_non_empty_boundary)
             {
                 indices.Sort(0, indices.Size());
                 for (int i_1 = 0, n = indices.Size(); i_1 < n; i_1++)
                 {
                     if (indices.Get(i_1) == com.epl.geometry.NumberUtils.IntMax())
                     {
                         break;
                     }
                     mpImpl.GetPointByVal(indices.Get(i_1), point);
                     dst.Add(point);
                 }
             }
         }
     }
     if (only_check_non_empty_boundary)
     {
         return(null);
     }
     return(dst);
 }