示例#1
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");
     }
 }
示例#2
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);
 }
示例#3
0
        public override bool Equals(com.epl.geometry.AttributeStreamBase other, int start, int end)
        {
            if (other == null)
            {
                return(false);
            }
            if (!(other is com.epl.geometry.AttributeStreamOfInt8))
            {
                return(false);
            }
            com.epl.geometry.AttributeStreamOfInt8 _other = (com.epl.geometry.AttributeStreamOfInt8)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);
        }
示例#4
0
        // Mirrors wkt
        private static void ExportPolylineToGeoJson_(int export_flags, com.epl.geometry.Polyline polyline, com.epl.geometry.JsonWriter json_writer)
        {
            com.epl.geometry.MultiPathImpl polyline_impl = (com.epl.geometry.MultiPathImpl)polyline._getImpl();
            int point_count = polyline_impl.GetPointCount();
            int path_count  = polyline_impl.GetPathCount();

            if (point_count > 0 && path_count == 0)
            {
                throw new com.epl.geometry.GeometryException("corrupted geometry");
            }
            int  precision   = 17 - (31 & (export_flags >> 13));
            bool bFixedPoint = (com.epl.geometry.GeoJsonExportFlags.geoJsonExportPrecisionFixedPoint & export_flags) != 0;
            bool b_export_zs = polyline_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportStripZs) == 0;
            bool b_export_ms = polyline_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportStripMs) == 0;

            if (!b_export_zs && b_export_ms)
            {
                throw new System.ArgumentException("invalid argument");
            }
            com.epl.geometry.AttributeStreamOfDbl   position   = null;
            com.epl.geometry.AttributeStreamOfDbl   zs         = null;
            com.epl.geometry.AttributeStreamOfDbl   ms         = null;
            com.epl.geometry.AttributeStreamOfInt8  path_flags = null;
            com.epl.geometry.AttributeStreamOfInt32 paths      = null;
            if (point_count > 0)
            {
                position   = (com.epl.geometry.AttributeStreamOfDbl)polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
                path_flags = polyline_impl.GetPathFlagsStreamRef();
                paths      = polyline_impl.GetPathStreamRef();
                if (b_export_zs)
                {
                    if (polyline_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z))
                    {
                        zs = (com.epl.geometry.AttributeStreamOfDbl)polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
                    }
                }
                if (b_export_ms)
                {
                    if (polyline_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M))
                    {
                        ms = (com.epl.geometry.AttributeStreamOfDbl)polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M);
                    }
                }
            }
            if ((export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportPreferMultiGeometry) == 0 && path_count <= 1)
            {
                LineStringTaggedText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, json_writer);
            }
            else
            {
                MultiLineStringTaggedText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, path_count, json_writer);
            }
        }
        internal static void ExportPolylineToWkt(int export_flags, com.epl.geometry.Polyline polyline, System.Text.StringBuilder @string)
        {
            com.epl.geometry.MultiPathImpl polyline_impl = (com.epl.geometry.MultiPathImpl)polyline._getImpl();
            int point_count = polyline_impl.GetPointCount();
            int path_count  = polyline_impl.GetPathCount();

            if (point_count > 0 && path_count == 0)
            {
                throw new com.epl.geometry.GeometryException("corrupted geometry");
            }
            int  precision   = 17 - (7 & (export_flags >> 13));
            bool b_export_zs = polyline_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (export_flags & com.epl.geometry.WktExportFlags.wktExportStripZs) == 0;
            bool b_export_ms = polyline_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (export_flags & com.epl.geometry.WktExportFlags.wktExportStripMs) == 0;

            com.epl.geometry.AttributeStreamOfDbl   position   = null;
            com.epl.geometry.AttributeStreamOfDbl   zs         = null;
            com.epl.geometry.AttributeStreamOfDbl   ms         = null;
            com.epl.geometry.AttributeStreamOfInt8  path_flags = null;
            com.epl.geometry.AttributeStreamOfInt32 paths      = null;
            if (point_count > 0)
            {
                position   = (com.epl.geometry.AttributeStreamOfDbl)polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
                path_flags = polyline_impl.GetPathFlagsStreamRef();
                paths      = polyline_impl.GetPathStreamRef();
                if (b_export_zs)
                {
                    if (polyline_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z))
                    {
                        zs = (com.epl.geometry.AttributeStreamOfDbl)(polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z));
                    }
                }
                if (b_export_ms)
                {
                    if (polyline_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M))
                    {
                        ms = (com.epl.geometry.AttributeStreamOfDbl)(polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M));
                    }
                }
            }
            if ((export_flags & com.epl.geometry.WktExportFlags.wktExportLineString) != 0)
            {
                if (path_count > 1)
                {
                    throw new System.ArgumentException("Cannot export a LineString with specified export flags: " + export_flags);
                }
                LineStringTaggedText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, @string);
            }
            else
            {
                MultiLineStringTaggedText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, path_count, @string);
            }
        }
        /// <summary>Creates a new attribute stream of given persistence type and size.</summary>
        /// <param name="persistence">The persistence type of the stream (see VertexDescription).</param>
        /// <param name="size">
        /// The number of elements (floats, doubles, or 32 bit integers)
        /// of the given type in the stream.
        /// </param>
        /// <param name="defaultValue">The default value to fill the stream with.</param>
        public static com.epl.geometry.AttributeStreamBase CreateAttributeStreamWithPersistence(int persistence, int size, double defaultValue)
        {
            com.epl.geometry.AttributeStreamBase newStream;
            switch (persistence)
            {
            case (com.epl.geometry.VertexDescription.Persistence.enumFloat):
            {
                newStream = new com.epl.geometry.AttributeStreamOfFloat(size, (float)defaultValue);
                break;
            }

            case (com.epl.geometry.VertexDescription.Persistence.enumDouble):
            {
                newStream = new com.epl.geometry.AttributeStreamOfDbl(size, (double)defaultValue);
                break;
            }

            case (com.epl.geometry.VertexDescription.Persistence.enumInt32):
            {
                newStream = new com.epl.geometry.AttributeStreamOfInt32(size, (int)defaultValue);
                break;
            }

            case (com.epl.geometry.VertexDescription.Persistence.enumInt64):
            {
                newStream = new com.epl.geometry.AttributeStreamOfInt64(size, (long)defaultValue);
                break;
            }

            case (com.epl.geometry.VertexDescription.Persistence.enumInt8):
            {
                newStream = new com.epl.geometry.AttributeStreamOfInt8(size, unchecked ((byte)defaultValue));
                break;
            }

            case (com.epl.geometry.VertexDescription.Persistence.enumInt16):
            {
                newStream = new com.epl.geometry.AttributeStreamOfInt16(size, (short)defaultValue);
                break;
            }

            default:
            {
                throw new com.epl.geometry.GeometryException("Internal Error");
            }
            }
            return(newStream);
        }
示例#7
0
        public AttributeStreamOfInt8(com.epl.geometry.AttributeStreamOfInt8 other, int maxSize)
        {
            m_size = other.Size();
            if (m_size > maxSize)
            {
                m_size = maxSize;
            }
            int sz = m_size;

            if (sz < 2)
            {
                sz = 2;
            }
            m_buffer = new byte[sz];
            System.Array.Copy(other.m_buffer, 0, m_buffer, 0, m_size);
        }
        internal static int MultiLineStringText(com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, com.epl.geometry.AttributeStreamOfInt32 paths, com.epl.geometry.AttributeStreamOfInt8 path_flags, com.epl.geometry.WktParser
                                                wkt_parser)
        {
            // At start of MultiLineStringText
            int current_token     = wkt_parser.CurrentToken();
            int total_point_count = 0;

            if (current_token == com.epl.geometry.WktParser.WktToken.empty)
            {
                return(total_point_count);
            }
            current_token = wkt_parser.NextToken();
            while (current_token != com.epl.geometry.WktParser.WktToken.right_paren)
            {
                // At start of LineStringText
                int point_count = LineStringText(false, zs, ms, position, paths, path_flags, wkt_parser);
                total_point_count += point_count;
                current_token      = wkt_parser.NextToken();
            }
            return(total_point_count);
        }
示例#9
0
        // Mirrors wkt
        private static void MultiLineStringText_(int precision, bool bFixedPoint, bool b_export_zs, bool b_export_ms, com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, com.epl.geometry.AttributeStreamOfInt8
                                                 path_flags, com.epl.geometry.AttributeStreamOfInt32 paths, int path_count, com.epl.geometry.JsonWriter json_writer)
        {
            bool b_closed = ((path_flags.Read(0) & com.epl.geometry.PathFlags.enumClosed) != 0);

            LineStringText_(false, b_closed, precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, 0, paths.Read(1), json_writer);
            for (int path = 1; path < path_count; path++)
            {
                b_closed = ((path_flags.Read(path) & com.epl.geometry.PathFlags.enumClosed) != 0);
                int istart = paths.Read(path);
                int iend   = paths.Read(path + 1);
                LineStringText_(false, b_closed, precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, istart, iend, json_writer);
            }
        }
示例#10
0
        // Mirrors wkt
        private static void MultiPolygonText_(int precision, bool bFixedPoint, bool b_export_zs, bool b_export_ms, com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, com.epl.geometry.AttributeStreamOfInt8
                                              path_flags, com.epl.geometry.AttributeStreamOfInt32 paths, int polygon_count, int path_count, com.epl.geometry.JsonWriter json_writer)
        {
            int polygon_start = 0;
            int polygon_end   = 1;

            while (polygon_end < path_count && ((int)path_flags.Read(polygon_end) & com.epl.geometry.PathFlags.enumOGCStartPolygon) == 0)
            {
                polygon_end++;
            }
            PolygonText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, paths, polygon_start, polygon_end, json_writer);
            for (int ipolygon = 1; ipolygon < polygon_count; ipolygon++)
            {
                polygon_start = polygon_end;
                polygon_end++;
                while (polygon_end < path_count && ((int)path_flags.Read(polygon_end) & com.epl.geometry.PathFlags.enumOGCStartPolygon) == 0)
                {
                    polygon_end++;
                }
                PolygonText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, paths, polygon_start, polygon_end, json_writer);
            }
        }
示例#11
0
 public override void WriteRange(int startElement, int count, com.epl.geometry.AttributeStreamBase _src, int srcStart, bool bForward, int stride)
 {
     if (startElement < 0 || count < 0 || srcStart < 0)
     {
         throw new System.ArgumentException();
     }
     if (!bForward && (stride <= 0 || (count % stride != 0)))
     {
         throw new System.ArgumentException();
     }
     com.epl.geometry.AttributeStreamOfInt8 src = (com.epl.geometry.AttributeStreamOfInt8)_src;
     // the input
     // type must
     // match
     if (src.Size() < (int)(srcStart + count))
     {
         throw new System.ArgumentException();
     }
     if (count == 0)
     {
         return;
     }
     if (Size() < count + startElement)
     {
         Resize(count + startElement);
     }
     if (_src == (com.epl.geometry.AttributeStreamBase) this)
     {
         _selfWriteRangeImpl(startElement, count, srcStart, bForward, stride);
         return;
     }
     if (bForward)
     {
         int j      = startElement;
         int offset = srcStart;
         for (int i = 0; i < count; i++)
         {
             m_buffer[j] = src.m_buffer[offset];
             j++;
             offset++;
         }
     }
     else
     {
         int j      = startElement;
         int offset = srcStart + count - stride;
         if (stride == 1)
         {
             for (int i = 0; i < count; i++)
             {
                 m_buffer[j] = src.m_buffer[offset];
                 j++;
                 offset--;
             }
         }
         else
         {
             for (int i = 0, n = count / stride; i < n; i++)
             {
                 for (int k = 0; k < stride; k++)
                 {
                     m_buffer[j + k] = src.m_buffer[offset + k];
                 }
                 j      += stride;
                 offset -= stride;
             }
         }
     }
 }
示例#12
0
 public AttributeStreamOfInt8(com.epl.geometry.AttributeStreamOfInt8 other)
 {
     m_buffer = (byte[])other.m_buffer.Clone();
     m_size   = other.m_size;
 }
        internal static void MultiLineStringText_(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, com.epl.geometry.AttributeStreamOfInt8 path_flags, com.epl.geometry.AttributeStreamOfInt32
                                                  paths, int path_count, System.Text.StringBuilder @string)
        {
            bool b_closed = ((path_flags.Read(0) & com.epl.geometry.PathFlags.enumClosed) != 0);

            LineStringText_(false, b_closed, precision, b_export_zs, b_export_ms, zs, ms, position, paths, 0, @string);
            for (int path = 1; path < path_count; path++)
            {
                @string.Append(", ");
                b_closed = ((path_flags.Read(path) & com.epl.geometry.PathFlags.enumClosed) != 0);
                LineStringText_(false, b_closed, precision, b_export_zs, b_export_ms, zs, ms, position, paths, path, @string);
            }
        }
        internal static void LineStringTaggedText_(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, com.epl.geometry.AttributeStreamOfInt8 path_flags,
                                                   com.epl.geometry.AttributeStreamOfInt32 paths, System.Text.StringBuilder @string)
        {
            @string.Append("LINESTRING ");
            if (b_export_zs && b_export_ms)
            {
                @string.Append("ZM ");
            }
            else
            {
                if (b_export_zs && !b_export_ms)
                {
                    @string.Append("Z ");
                }
                else
                {
                    if (!b_export_zs && b_export_ms)
                    {
                        @string.Append("M ");
                    }
                }
            }
            if (position == null)
            {
                @string.Append("EMPTY");
                return;
            }
            bool b_closed = ((path_flags.Read(0) & com.epl.geometry.PathFlags.enumClosed) != 0);

            LineStringText_(false, b_closed, precision, b_export_zs, b_export_ms, zs, ms, position, paths, 0, @string);
        }
 internal static void MultiLineStringTaggedText_(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, com.epl.geometry.AttributeStreamOfInt8 path_flags
                                                 , com.epl.geometry.AttributeStreamOfInt32 paths, int path_count, System.Text.StringBuilder @string)
 {
     @string.Append("MULTILINESTRING ");
     if (b_export_zs && b_export_ms)
     {
         @string.Append("ZM ");
     }
     else
     {
         if (b_export_zs && !b_export_ms)
         {
             @string.Append("Z ");
         }
         else
         {
             if (!b_export_zs && b_export_ms)
             {
                 @string.Append("M ");
             }
         }
     }
     if (position == null)
     {
         @string.Append("EMPTY");
         return;
     }
     @string.Append('(');
     MultiLineStringText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, path_count, @string);
     @string.Append(')');
 }
        internal static com.epl.geometry.Geometry PolygonTaggedText(bool b_multi_polygon, int import_flags, com.epl.geometry.WktParser wkt_parser)
        {
            com.epl.geometry.MultiPath              multi_path;
            com.epl.geometry.MultiPathImpl          multi_path_impl;
            com.epl.geometry.AttributeStreamOfDbl   zs = null;
            com.epl.geometry.AttributeStreamOfDbl   ms = null;
            com.epl.geometry.AttributeStreamOfDbl   position;
            com.epl.geometry.AttributeStreamOfInt32 paths;
            com.epl.geometry.AttributeStreamOfInt8  path_flags;
            position        = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0);
            paths           = (com.epl.geometry.AttributeStreamOfInt32)com.epl.geometry.AttributeStreamBase.CreateIndexStream(1, 0);
            path_flags      = (com.epl.geometry.AttributeStreamOfInt8)com.epl.geometry.AttributeStreamBase.CreateByteStream(1, unchecked ((byte)0));
            multi_path      = new com.epl.geometry.Polygon();
            multi_path_impl = (com.epl.geometry.MultiPathImpl)multi_path._getImpl();
            int current_token = wkt_parser.NextToken();

            if (current_token == com.epl.geometry.WktParser.WktToken.attribute_z)
            {
                zs = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0, com.epl.geometry.NumberUtils.TheNaN);
                multi_path_impl.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                wkt_parser.NextToken();
            }
            else
            {
                if (current_token == com.epl.geometry.WktParser.WktToken.attribute_m)
                {
                    ms = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0, com.epl.geometry.NumberUtils.TheNaN);
                    multi_path_impl.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                    wkt_parser.NextToken();
                }
                else
                {
                    if (current_token == com.epl.geometry.WktParser.WktToken.attribute_zm)
                    {
                        zs = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0, com.epl.geometry.NumberUtils.TheNaN);
                        ms = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0, com.epl.geometry.NumberUtils.TheNaN);
                        multi_path_impl.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                        multi_path_impl.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                        wkt_parser.NextToken();
                    }
                }
            }
            int point_count;

            if (b_multi_polygon)
            {
                point_count = MultiPolygonText(zs, ms, position, paths, path_flags, wkt_parser);
            }
            else
            {
                point_count = PolygonText(zs, ms, position, paths, path_flags, 0, wkt_parser);
            }
            if (point_count != 0)
            {
                System.Diagnostics.Debug.Assert((2 * point_count == position.Size()));
                multi_path_impl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION, position);
                multi_path_impl.SetPathStreamRef(paths);
                multi_path_impl.SetPathFlagsStreamRef(path_flags);
                if (zs != null)
                {
                    multi_path_impl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z, zs);
                }
                if (ms != null)
                {
                    multi_path_impl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M, ms);
                }
                multi_path_impl.NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyAll);
                com.epl.geometry.AttributeStreamOfInt8 path_flags_clone = new com.epl.geometry.AttributeStreamOfInt8(path_flags);
                for (int i = 0; i < path_flags_clone.Size() - 1; i++)
                {
                    if (((int)path_flags_clone.Read(i) & (int)com.epl.geometry.PathFlags.enumOGCStartPolygon) != 0)
                    {
                        // Should
                        // be
                        // clockwise
                        if (!com.epl.geometry.InternalUtils.IsClockwiseRing(multi_path_impl, i))
                        {
                            multi_path_impl.ReversePath(i);
                        }
                    }
                    else
                    {
                        // make clockwise
                        // Should be counter-clockwise
                        if (com.epl.geometry.InternalUtils.IsClockwiseRing(multi_path_impl, i))
                        {
                            multi_path_impl.ReversePath(i);
                        }
                    }
                }
                // make
                // counter-clockwise
                multi_path_impl.SetPathFlagsStreamRef(path_flags_clone);
            }
            if ((import_flags & (int)com.epl.geometry.WktImportFlags.wktImportNonTrusted) == 0)
            {
                multi_path_impl.SetIsSimple(com.epl.geometry.MultiVertexGeometryImpl.GeometryXSimple.Weak, 0.0, false);
            }
            multi_path_impl.SetDirtyOGCFlags(false);
            return(multi_path);
        }
示例#17
0
        public void _updateSegment()
        {
            if (m_nextSegmentIndex < 0 || m_nextSegmentIndex >= m_segmentCount)
            {
                throw new System.IndexOutOfRangeException();
            }
            m_currentSegmentIndex = m_nextSegmentIndex;
            int startVertexIndex = GetStartPointIndex();

            m_parent._verifyAllStreams();
            com.epl.geometry.AttributeStreamOfInt8 segFlagStream = m_parent.GetSegmentFlagsStreamRef();
            int segFlag = com.epl.geometry.SegmentFlags.enumLineSeg;

            if (segFlagStream != null)
            {
                segFlag = (segFlagStream.Read(startVertexIndex) & com.epl.geometry.SegmentFlags.enumSegmentMask);
            }
            com.epl.geometry.VertexDescription vertexDescr = m_parent.GetDescription();
            switch (segFlag)
            {
            case com.epl.geometry.SegmentFlags.enumLineSeg:
            {
                if (m_line == null)
                {
                    m_line = new com.epl.geometry.Line();
                }
                m_currentSegment = (com.epl.geometry.Line)m_line;
                break;
            }

            case com.epl.geometry.SegmentFlags.enumBezierSeg:
            {
                throw com.epl.geometry.GeometryException.GeometryInternalError();
            }

            case com.epl.geometry.SegmentFlags.enumArcSeg:
            {
                // break;
                throw com.epl.geometry.GeometryException.GeometryInternalError();
            }

            default:
            {
                // break;
                throw com.epl.geometry.GeometryException.GeometryInternalError();
            }
            }
            m_currentSegment.AssignVertexDescription(vertexDescr);
            int endVertexIndex = GetEndPointIndex();

            m_parent.GetXY(startVertexIndex, m_dummyPoint);
            m_currentSegment.SetStartXY(m_dummyPoint);
            m_parent.GetXY(endVertexIndex, m_dummyPoint);
            m_currentSegment.SetEndXY(m_dummyPoint);
            for (int i = 1, nattr = vertexDescr.GetAttributeCount(); i < nattr; i++)
            {
                int semantics = vertexDescr.GetSemantics(i);
                int ncomp     = com.epl.geometry.VertexDescription.GetComponentCount(semantics);
                for (int ord = 0; ord < ncomp; ord++)
                {
                    double vs = m_parent.GetAttributeAsDbl(semantics, startVertexIndex, ord);
                    m_currentSegment.SetStartAttribute(semantics, ord, vs);
                    double ve = m_parent.GetAttributeAsDbl(semantics, endVertexIndex, ord);
                    m_currentSegment.SetEndAttribute(semantics, ord, ve);
                }
            }
        }
 internal static void PolygonTaggedText_(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, com.epl.geometry.AttributeStreamOfInt8 path_flags, com.epl.geometry.AttributeStreamOfInt32
                                         paths, int path_count, System.Text.StringBuilder @string)
 {
     @string.Append("POLYGON ");
     if (b_export_zs && b_export_ms)
     {
         @string.Append("ZM ");
     }
     else
     {
         if (b_export_zs && !b_export_ms)
         {
             @string.Append("Z ");
         }
         else
         {
             if (!b_export_zs && b_export_ms)
             {
                 @string.Append("M ");
             }
         }
     }
     if (position == null)
     {
         @string.Append("EMPTY");
         return;
     }
     PolygonText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, 0, path_count, @string);
 }
        internal static int PolygonText(com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, com.epl.geometry.AttributeStreamOfInt32 paths, com.epl.geometry.AttributeStreamOfInt8 path_flags, int total_point_count
                                        , com.epl.geometry.WktParser wkt_parser)
        {
            // At start of PolygonText
            int current_token = wkt_parser.CurrentToken();

            if (current_token == com.epl.geometry.WktParser.WktToken.empty)
            {
                return(total_point_count);
            }
            bool b_first_line_string = true;

            current_token = wkt_parser.NextToken();
            while (current_token != com.epl.geometry.WktParser.WktToken.right_paren)
            {
                // At start of LineStringText
                int point_count = LineStringText(true, zs, ms, position, paths, path_flags, wkt_parser);
                if (point_count != 0)
                {
                    if (b_first_line_string)
                    {
                        b_first_line_string = false;
                        path_flags.SetBits(path_flags.Size() - 2, unchecked ((byte)com.epl.geometry.PathFlags.enumOGCStartPolygon));
                    }
                    path_flags.SetBits(path_flags.Size() - 2, unchecked ((byte)com.epl.geometry.PathFlags.enumClosed));
                    total_point_count += point_count;
                }
                current_token = wkt_parser.NextToken();
            }
            return(total_point_count);
        }
        internal static void MultiPolygonText_(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, com.epl.geometry.AttributeStreamOfInt8 path_flags, com.epl.geometry.AttributeStreamOfInt32
                                               paths, int polygon_count, int path_count, System.Text.StringBuilder @string)
        {
            int polygon_start = 0;
            int polygon_end   = 1;

            while (polygon_end < path_count && (path_flags.Read(polygon_end) & com.epl.geometry.PathFlags.enumOGCStartPolygon) == 0)
            {
                polygon_end++;
            }
            PolygonText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, polygon_start, polygon_end, @string);
            for (int ipolygon = 1; ipolygon < polygon_count; ipolygon++)
            {
                polygon_start = polygon_end;
                polygon_end++;
                while (polygon_end < path_count && (path_flags.Read(polygon_end) & com.epl.geometry.PathFlags.enumOGCStartPolygon) == 0)
                {
                    polygon_end++;
                }
                @string.Append(", ");
                PolygonText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, polygon_start, polygon_end, @string);
            }
        }
        internal static int LineStringText(bool b_ring, com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, com.epl.geometry.AttributeStreamOfInt32 paths, com.epl.geometry.AttributeStreamOfInt8 path_flags
                                           , com.epl.geometry.WktParser wkt_parser)
        {
            // At start of LineStringText
            int current_token = wkt_parser.CurrentToken();
            int point_count   = 0;

            if (current_token == com.epl.geometry.WktParser.WktToken.empty)
            {
                return(point_count);
            }
            bool   b_start_path = true;
            double startx       = com.epl.geometry.NumberUtils.TheNaN;
            double starty       = com.epl.geometry.NumberUtils.TheNaN;
            double startz       = com.epl.geometry.NumberUtils.TheNaN;
            double startm       = com.epl.geometry.NumberUtils.TheNaN;

            current_token = wkt_parser.NextToken();
            while (current_token != com.epl.geometry.WktParser.WktToken.right_paren)
            {
                // At start of x
                double x = wkt_parser.CurrentNumericLiteral();
                wkt_parser.NextToken();
                double y = wkt_parser.CurrentNumericLiteral();
                wkt_parser.NextToken();
                double z = com.epl.geometry.NumberUtils.TheNaN;
                double m = com.epl.geometry.NumberUtils.TheNaN;
                if (wkt_parser.HasZs())
                {
                    z = wkt_parser.CurrentNumericLiteral();
                    wkt_parser.NextToken();
                }
                if (wkt_parser.HasMs())
                {
                    m = wkt_parser.CurrentNumericLiteral();
                    wkt_parser.NextToken();
                }
                current_token = wkt_parser.CurrentToken();
                bool b_add_point = true;
                if (b_ring && point_count >= 2 && current_token == com.epl.geometry.WktParser.WktToken.right_paren)
                {
                    // If the last point in the ring is not equal to the start
                    // point, then let's add it.
                    if ((startx == x || (com.epl.geometry.NumberUtils.IsNaN(startx) && com.epl.geometry.NumberUtils.IsNaN(x))) && (starty == y || (com.epl.geometry.NumberUtils.IsNaN(starty) && com.epl.geometry.NumberUtils.IsNaN(y))) && (!wkt_parser.HasZs() || startz == z || (com.epl.geometry.NumberUtils
                                                                                                                                                                                                                                                                                    .IsNaN(startz) && com.epl.geometry.NumberUtils.IsNaN(z))) && (!wkt_parser.HasMs() || startm == m || (com.epl.geometry.NumberUtils.IsNaN(startm) && com.epl.geometry.NumberUtils.IsNaN(m))))
                    {
                        b_add_point = false;
                    }
                }
                if (b_add_point)
                {
                    if (b_start_path)
                    {
                        b_start_path = false;
                        startx       = x;
                        starty       = y;
                        startz       = z;
                        startm       = m;
                    }
                    point_count++;
                    AddToStreams(zs, ms, position, x, y, z, m);
                }
            }
            if (point_count == 1)
            {
                point_count++;
                AddToStreams(zs, ms, position, startx, starty, startz, startm);
            }
            paths.Add(position.Size() / 2);
            path_flags.Add(unchecked ((byte)0));
            return(point_count);
        }
 internal static void PolygonText_(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, com.epl.geometry.AttributeStreamOfInt8 path_flags, com.epl.geometry.AttributeStreamOfInt32
                                   paths, int polygon_start, int polygon_end, System.Text.StringBuilder @string)
 {
     @string.Append('(');
     LineStringText_(true, true, precision, b_export_zs, b_export_ms, zs, ms, position, paths, polygon_start, @string);
     for (int path = polygon_start + 1; path < polygon_end; path++)
     {
         @string.Append(", ");
         LineStringText_(true, true, precision, b_export_zs, b_export_ms, zs, ms, position, paths, path, @string);
     }
     @string.Append(')');
 }
示例#23
0
 // Mirrors wkt
 private static void MultiLineStringTaggedText_(int precision, bool bFixedPoint, bool b_export_zs, bool b_export_ms, com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, com.epl.geometry.AttributeStreamOfInt8
                                                path_flags, com.epl.geometry.AttributeStreamOfInt32 paths, int path_count, com.epl.geometry.JsonWriter json_writer)
 {
     json_writer.AddFieldName("type");
     json_writer.AddValueString("MultiLineString");
     json_writer.AddFieldName("coordinates");
     if (position == null)
     {
         json_writer.StartArray();
         json_writer.EndArray();
         return;
     }
     json_writer.StartArray();
     MultiLineStringText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, path_count, json_writer);
     json_writer.EndArray();
 }
 /// <summary>Creates a new attribute stream for storing bytes.</summary>
 /// <param name="size">The number of elements in the stream.</param>
 /// <param name="defaultValue">The default value to fill the stream with.</param>
 public static com.epl.geometry.AttributeStreamBase CreateByteStream(int size, byte defaultValue)
 {
     com.epl.geometry.AttributeStreamBase newStream = new com.epl.geometry.AttributeStreamOfInt8(size, defaultValue);
     return(newStream);
 }
示例#25
0
        // Mirrors wkt
        private static void LineStringTaggedText_(int precision, bool bFixedPoint, bool b_export_zs, bool b_export_ms, com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, com.epl.geometry.AttributeStreamOfInt8
                                                  path_flags, com.epl.geometry.AttributeStreamOfInt32 paths, com.epl.geometry.JsonWriter json_writer)
        {
            json_writer.AddFieldName("type");
            json_writer.AddValueString("LineString");
            json_writer.AddFieldName("coordinates");
            if (position == null)
            {
                json_writer.StartArray();
                json_writer.EndArray();
                return;
            }
            bool b_closed = ((path_flags.Read(0) & com.epl.geometry.PathFlags.enumClosed) != 0);

            LineStringText_(false, b_closed, precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, 0, paths.Read(1), json_writer);
        }
示例#26
0
        public static void TestIntervalTree_RandomConstruction()
        {
            int pointcount = 0;
            int passcount  = 1000;
            int figureSize = 50;

            com.epl.geometry.Envelope env = new com.epl.geometry.Envelope();
            env.SetCoords(-10000, -10000, 10000, 10000);
            com.epl.geometry.RandomCoordinateGenerator generator = new com.epl.geometry.RandomCoordinateGenerator(System.Math.Max(figureSize, 10000), env, 0.001);
            System.Random random   = new System.Random(2013);
            int           rand_max = 98765;

            System.Collections.Generic.List <com.epl.geometry.Envelope1D> intervals = new System.Collections.Generic.List <com.epl.geometry.Envelope1D>();
            com.epl.geometry.AttributeStreamOfInt8 intervalsFound = new com.epl.geometry.AttributeStreamOfInt8(0);
            for (int i = 0; i < passcount; i++)
            {
                int r = figureSize;
                if (r < 3)
                {
                    continue;
                }
                com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon();
                com.epl.geometry.Point   pt;
                for (int j = 0; j < r; j++)
                {
                    int  rand       = random.Next(rand_max);
                    bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95);
                    pt = generator.GetRandomCoord();
                    if (j == 0 || bRandomNew)
                    {
                        poly.StartPath(pt);
                    }
                    else
                    {
                        poly.LineTo(pt);
                    }
                }
                {
                    intervals.Clear();
                    com.epl.geometry.SegmentIterator seg_iter = poly.QuerySegmentIterator();
                    com.epl.geometry.Envelope1D      interval;
                    com.epl.geometry.Envelope1D      range = poly.QueryInterval(com.epl.geometry.VertexDescription.Semantics.POSITION, 0);
                    range.vmin -= 0.01;
                    range.vmax += 0.01;
                    while (seg_iter.NextPath())
                    {
                        while (seg_iter.HasNextSegment())
                        {
                            com.epl.geometry.Segment segment = seg_iter.NextSegment();
                            interval = segment.QueryInterval(com.epl.geometry.VertexDescription.Semantics.POSITION, 0);
                            intervals.Add(interval);
                        }
                    }
                    intervalsFound.Resize(intervals.Count, 0);
                    // Just test construction for assertions
                    com.epl.geometry.IntervalTreeImpl intervalTree = new com.epl.geometry.IntervalTreeImpl(true);
                    Construct(intervalTree, intervals);
                    for (int j_1 = 0; j_1 < intervals.Count; j_1++)
                    {
                        intervalTree.Insert(j_1);
                    }
                    com.epl.geometry.IntervalTreeImpl.IntervalTreeIteratorImpl iterator = intervalTree.GetIterator(range, 0.0);
                    int count = 0;
                    int handle;
                    while ((handle = iterator.Next()) != -1)
                    {
                        count++;
                        intervalsFound.Write(handle, unchecked ((byte)1));
                    }
                    NUnit.Framework.Assert.IsTrue(count == intervals.Count);
                    for (int j_2 = 0; j_2 < intervalsFound.Size(); j_2++)
                    {
                        interval = intervals[j_2];
                        NUnit.Framework.Assert.IsTrue(intervalsFound.Read(j_2) == 1);
                    }
                    for (int j_3 = 0; j_3 < intervals.Count >> 1; j_3++)
                    {
                        intervalTree.Remove(j_3);
                    }
                    iterator.ResetIterator(range, 0.0);
                    count = 0;
                    while ((handle = iterator.Next()) != -1)
                    {
                        count++;
                        intervalsFound.Write(handle, unchecked ((byte)1));
                    }
                    NUnit.Framework.Assert.IsTrue(count == intervals.Count - (intervals.Count >> 1));
                    for (int j_4 = (intervals.Count >> 1); j_4 < intervals.Count; j_4++)
                    {
                        intervalTree.Remove(j_4);
                    }
                }
            }
        }
        /// <exception cref="System.Exception"/>
        private static com.epl.geometry.Geometry ImportFromJsonMultiPath(bool b_polygon, com.epl.geometry.JsonReader parser, com.epl.geometry.AttributeStreamOfDbl @as, com.epl.geometry.AttributeStreamOfDbl bs)
        {
            if (parser.CurrentToken() != com.epl.geometry.JsonReader.Token.START_ARRAY)
            {
                throw new com.epl.geometry.GeometryException("failed to parse multipath: array of array of vertices is expected");
            }
            com.epl.geometry.MultiPath multipath;
            if (b_polygon)
            {
                multipath = new com.epl.geometry.Polygon();
            }
            else
            {
                multipath = new com.epl.geometry.Polyline();
            }
            com.epl.geometry.AttributeStreamOfInt32 parts     = (com.epl.geometry.AttributeStreamOfInt32)com.epl.geometry.AttributeStreamBase.CreateIndexStream(0);
            com.epl.geometry.AttributeStreamOfDbl   position  = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(2, 0);
            com.epl.geometry.AttributeStreamOfInt8  pathFlags = (com.epl.geometry.AttributeStreamOfInt8)com.epl.geometry.AttributeStreamBase.CreateByteStream(0);
            // set up min max variables
            double[] buf          = new double[4];
            double[] start        = new double[4];
            int      point_count  = 0;
            int      path_count   = 0;
            byte     pathFlag     = b_polygon ? unchecked ((byte)com.epl.geometry.PathFlags.enumClosed) : 0;
            int      requiredSize = b_polygon ? 3 : 2;

            // At start of rings
            while (parser.NextToken() != com.epl.geometry.JsonReader.Token.END_ARRAY)
            {
                if (parser.CurrentToken() != com.epl.geometry.JsonReader.Token.START_ARRAY)
                {
                    throw new com.epl.geometry.GeometryException("failed to parse multipath: ring/path array is expected");
                }
                int  pathPointCount = 0;
                bool b_first        = true;
                int  sz             = 0;
                int  szstart        = 0;
                parser.NextToken();
                while (parser.CurrentToken() != com.epl.geometry.JsonReader.Token.END_ARRAY)
                {
                    if (parser.CurrentToken() != com.epl.geometry.JsonReader.Token.START_ARRAY)
                    {
                        throw new com.epl.geometry.GeometryException("failed to parse multipath: array is expected, rings/paths vertices consist of arrays of cooridinates");
                    }
                    sz = 0;
                    while (parser.NextToken() != com.epl.geometry.JsonReader.Token.END_ARRAY)
                    {
                        buf[sz++] = ReadDouble(parser);
                    }
                    if (sz < 2)
                    {
                        throw new com.epl.geometry.GeometryException("failed to parse multipath: each vertex array has to have at least 2 elements");
                    }
                    parser.NextToken();
                    do
                    {
                        if (position.Size() == point_count * 2)
                        {
                            int c = point_count * 3;
                            if (c % 2 != 0)
                            {
                                c++;
                            }
                            // have to be even
                            if (c < 8)
                            {
                                c = 8;
                            }
                            else
                            {
                                if (c < 32)
                                {
                                    c = 32;
                                }
                            }
                            position.Resize(c);
                        }
                        position.Write(2 * point_count, buf[0]);
                        position.Write(2 * point_count + 1, buf[1]);
                        if (@as.Size() == point_count)
                        {
                            int c = (point_count * 3) / 2;
                            // have to be even
                            if (c < 4)
                            {
                                c = 4;
                            }
                            else
                            {
                                if (c < 16)
                                {
                                    c = 16;
                                }
                            }
                            @as.Resize(c);
                        }
                        if (sz > 2)
                        {
                            @as.Write(point_count, buf[2]);
                        }
                        else
                        {
                            @as.Write(point_count, com.epl.geometry.NumberUtils.NaN());
                        }
                        if (bs.Size() == point_count)
                        {
                            int c = (point_count * 3) / 2;
                            // have to be even
                            if (c < 4)
                            {
                                c = 4;
                            }
                            else
                            {
                                if (c < 16)
                                {
                                    c = 16;
                                }
                            }
                            bs.Resize(c);
                        }
                        if (sz > 3)
                        {
                            bs.Write(point_count, buf[3]);
                        }
                        else
                        {
                            bs.Write(point_count, com.epl.geometry.NumberUtils.NaN());
                        }
                        if (b_first)
                        {
                            path_count++;
                            parts.Add(point_count);
                            pathFlags.Add(pathFlag);
                            b_first  = false;
                            szstart  = sz;
                            start[0] = buf[0];
                            start[1] = buf[1];
                            start[2] = buf[2];
                            start[3] = buf[3];
                        }
                        point_count++;
                        pathPointCount++;
                    }while (pathPointCount < requiredSize && parser.CurrentToken() == com.epl.geometry.JsonReader.Token.END_ARRAY);
                }
                if (b_polygon && pathPointCount > requiredSize && sz == szstart && start[0] == buf[0] && start[1] == buf[1] && start[2] == buf[2] && start[3] == buf[3])
                {
                    // remove the end point that is equal to the start point.
                    point_count--;
                    pathPointCount--;
                }
                if (pathPointCount == 0)
                {
                    continue;
                }
            }
            // skip empty paths
            if (point_count != 0)
            {
                parts.Resize(path_count);
                pathFlags.Resize(path_count);
                if (point_count > 0)
                {
                    parts.Add(point_count);
                    pathFlags.Add(unchecked ((byte)0));
                }
                com.epl.geometry.MultiPathImpl mp_impl = (com.epl.geometry.MultiPathImpl)multipath._getImpl();
                mp_impl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION, position);
                mp_impl.SetPathFlagsStreamRef(pathFlags);
                mp_impl.SetPathStreamRef(parts);
            }
            return(multipath);
        }