private bool Initialize_()
 {
     m_envelope_handle_a = -1;
     m_envelope_handle_b = -1;
     if (m_envelopes_red.Count < 10)
     {
         m_sweep_index_red = m_envelopes_red.Count;
         m_function        = com.epl.geometry.Envelope2DIntersectorImpl.State.sweepBruteForce;
         return(true);
     }
     if (m_interval_tree_red == null)
     {
         m_interval_tree_red      = new com.epl.geometry.IntervalTreeImpl(true);
         m_sorted_end_indices_red = new com.epl.geometry.AttributeStreamOfInt32(0);
     }
     m_interval_tree_red.AddEnvelopesRef(m_envelopes_red);
     if (m_iterator_red == null)
     {
         m_iterator_red = m_interval_tree_red.GetIterator();
     }
     m_sorted_end_indices_red.Reserve(2 * m_envelopes_red.Count);
     m_sorted_end_indices_red.Resize(0);
     for (int i = 0; i < 2 * m_envelopes_red.Count; i++)
     {
         m_sorted_end_indices_red.Add(i);
     }
     SortYEndIndices_(m_sorted_end_indices_red, 0, 2 * m_envelopes_red.Count, true);
     m_sweep_index_red = 2 * m_envelopes_red.Count;
     m_function        = com.epl.geometry.Envelope2DIntersectorImpl.State.sweep;
     // overwrite initialize_
     return(true);
 }
        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 JsonStringWriter()
 {
     m_jsonString    = new System.Text.StringBuilder();
     m_functionStack = new com.epl.geometry.AttributeStreamOfInt32(0);
     m_functionStack.Add(com.epl.geometry.JsonWriter.State.accept);
     m_functionStack.Add(com.epl.geometry.JsonWriter.State.start);
 }
Пример #4
0
 public AttributeStreamOfInt32(com.epl.geometry.AttributeStreamOfInt32 other)
 {
     // for (int i = 0; i < size; i++)
     // m_buffer[i] = defaultValue;
     m_buffer = (int[])other.m_buffer.Clone();
     m_size   = other.m_size;
 }
 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(')');
 }
Пример #6
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.AttributeStreamOfInt32))
            {
                return(false);
            }
            com.epl.geometry.AttributeStreamOfInt32 _other = (com.epl.geometry.AttributeStreamOfInt32)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);
        }
        /// <summary>Creates a new attribute stream for storing vertex indices.</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 CreateIndexStream(int size, int defaultValue)
        {
            int persistence = com.epl.geometry.VertexDescription.Persistence.enumInt32;

            // VertexDescription.getPersistenceFromInt(NumberUtils::SizeOf((int)0));
            com.epl.geometry.AttributeStreamBase newStream;
            switch (persistence)
            {
            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;
            }

            default:
            {
                throw new com.epl.geometry.GeometryException("Internal Error");
            }
            }
            return(newStream);
        }
Пример #8
0
 public BucketSort()
 {
     m_buckets          = new com.epl.geometry.AttributeStreamOfInt32(0);
     m_bucketed_indices = new com.epl.geometry.AttributeStreamOfInt32(0);
     m_min_value        = 1;
     m_max_value        = -1;
     m_dy = com.epl.geometry.NumberUtils.TheNaN;
 }
Пример #9
0
 internal void ResetParser(string @string)
 {
     if (m_function_stack == null)
     {
         m_function_stack = new com.epl.geometry.AttributeStreamOfInt32(0);
     }
     Reset_();
     m_wkt_string = @string;
 }
 // *********** Helpers for Bucket sort**************
 private void SortYEndIndices_(com.epl.geometry.AttributeStreamOfInt32 end_indices, int begin_, int end_, bool b_red)
 {
     if (m_bucket_sort == null)
     {
         m_bucket_sort = new com.epl.geometry.BucketSort();
     }
     com.epl.geometry.Envelope2DIntersectorImpl.Envelope2DBucketSortHelper sorter = new com.epl.geometry.Envelope2DIntersectorImpl.Envelope2DBucketSortHelper(this, b_red);
     m_bucket_sort.Sort(end_indices, begin_, end_, sorter);
 }
Пример #11
0
 public IndexHashTable(int size, com.epl.geometry.IndexHashTable.HashFunction hashFunction)
 {
     //this is aimed to speedup the find
     //operation and allows to have less buckets.
     // Create hash table. size is the bin count in the table. The hashFunction
     // is the function to use.
     m_hashBuckets = new com.epl.geometry.AttributeStreamOfInt32(size, NullNode());
     m_lists       = new com.epl.geometry.IndexMultiList();
     m_hash        = hashFunction;
     m_bit_filter  = new int[(size * 10 + 31) >> 5];
 }
Пример #12
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);
            }
        }
Пример #14
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);
            }
        }
 internal virtual void StartRedConstruction()
 {
     Reset_();
     m_b_add_red = true;
     if (m_envelopes_red == null)
     {
         m_elements_red  = new com.epl.geometry.AttributeStreamOfInt32(0);
         m_envelopes_red = new System.Collections.Generic.List <com.epl.geometry.Envelope2D>(0);
     }
     else
     {
         m_elements_red.ResizePreserveCapacity(0);
         m_envelopes_red.Clear();
     }
 }
        /// <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);
        }
Пример #17
0
        public AttributeStreamOfInt32(com.epl.geometry.AttributeStreamOfInt32 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 int[sz];
            System.Array.Copy(other.m_buffer, 0, m_buffer, 0, m_size);
        }
Пример #18
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);
        }
Пример #19
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();
 }
Пример #20
0
 internal virtual void ProcessBunchForRingOrientationRemoveEdges_(com.epl.geometry.AttributeStreamOfInt32 bunch)
 {
     // remove all nodes that go out of scope
     for (int i = 0, n = bunch.Size(); i < n; i++)
     {
         int vertex = bunch.Get(i);
         int node1  = m_shape.GetUserIndex(vertex, m_node_1_user_index);
         int node2  = m_shape.GetUserIndex(vertex, m_node_2_user_index);
         if (node1 != -1)
         {
             int edge = m_AET.GetElement(node1);
             m_edges.FreeEdge(edge);
             m_shape.SetUserIndex(vertex, m_node_1_user_index, -1);
         }
         if (node2 != -1)
         {
             int edge = m_AET.GetElement(node2);
             m_edges.FreeEdge(edge);
             m_shape.SetUserIndex(vertex, m_node_2_user_index, -1);
         }
         int reused_node = -1;
         if (node1 != -1 && node2 != -1)
         {
             // terminating vertex
             m_AET.DeleteNode(node1, -1);
             m_AET.DeleteNode(node2, -1);
             bunch.Set(i, -1);
         }
         else
         {
             reused_node = node1 != -1 ? node1 : node2;
         }
         if (reused_node != -1)
         {
             // this vertex is a part of vertical chain.
             // Sorted order in AET did not change, so
             // reuse the AET node.
             if (!InsertEdge_(vertex, reused_node))
             {
                 m_AET.DeleteNode(reused_node, -1);
             }
             // horizontal edge was not
             // inserted
             bunch.Set(i, -1);
         }
     }
 }
Пример #21
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);
            }
        }
 private bool InitializeBlue_()
 {
     m_envelope_handle_a = -1;
     m_envelope_handle_b = -1;
     if (m_envelopes_red.Count < 10 || m_envelopes_blue.Count < 10)
     {
         m_sweep_index_red = m_envelopes_red.Count;
         m_function        = com.epl.geometry.Envelope2DIntersectorImpl.State.sweepRedBlueBruteForce;
         return(true);
     }
     if (m_interval_tree_blue == null)
     {
         m_interval_tree_blue      = new com.epl.geometry.IntervalTreeImpl(true);
         m_sorted_end_indices_blue = new com.epl.geometry.AttributeStreamOfInt32(0);
     }
     m_interval_tree_blue.AddEnvelopesRef(m_envelopes_blue);
     if (m_iterator_blue == null)
     {
         m_iterator_blue = m_interval_tree_blue.GetIterator();
     }
     m_sorted_end_indices_blue.Reserve(2 * m_envelopes_blue.Count);
     m_sorted_end_indices_blue.Resize(0);
     for (int i = 0; i < 2 * m_envelopes_blue.Count; i++)
     {
         m_sorted_end_indices_blue.Add(i);
     }
     SortYEndIndices_(m_sorted_end_indices_blue, 0, m_sorted_end_indices_blue.Size(), false);
     m_sweep_index_blue = m_sorted_end_indices_blue.Size();
     if (m_queued_list_blue != -1)
     {
         m_queued_envelopes.DeleteList(m_queued_list_blue);
         m_queued_indices_blue.Resize(0);
         m_queued_list_blue = -1;
     }
     m_function = com.epl.geometry.Envelope2DIntersectorImpl.State.sweepRedBlue;
     // overwrite initialize_
     return(ResetRed_());
 }
Пример #23
0
            internal int NewEdge(int vertex)
            {
                if (m_first_free != -1)
                {
                    int index = m_first_free;
                    m_first_free = m_end_1_nodes.Get(index);
                    m_end_1_nodes.Set(index, vertex);
                    m_end_2_nodes.Set(index, m_shape.GetNextVertex(vertex));
                    return(index);
                }
                else
                {
                    if (m_end_1_nodes == null)
                    {
                        m_end_1_nodes = new com.epl.geometry.AttributeStreamOfInt32(0);
                        m_end_2_nodes = new com.epl.geometry.AttributeStreamOfInt32(0);
                    }
                }
                int index_1 = m_end_1_nodes.Size();

                m_end_1_nodes.Add(vertex);
                m_end_2_nodes.Add(m_shape.GetNextVertex(vertex));
                return(index_1);
            }
        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);
                    }
                }
            }
        }
Пример #25
0
        // no cuts
        private void Generate_polygon_cuts_()
        {
            com.epl.geometry.AttributeStreamOfInt32 cutHandles = new com.epl.geometry.AttributeStreamOfInt32(0);
            com.epl.geometry.EditShape shape = new com.epl.geometry.EditShape();
            int sideIndex    = shape.CreateGeometryUserIndex();
            int cutteeHandle = shape.AddGeometry(m_cuttee);
            int cutterHandle = shape.AddGeometry(m_cutter);

            com.epl.geometry.TopologicalOperations topoOp = new com.epl.geometry.TopologicalOperations();
            try
            {
                topoOp.SetEditShapeCrackAndCluster(shape, m_tolerance, m_progressTracker);
                topoOp.Cut(sideIndex, cutteeHandle, cutterHandle, cutHandles);
                com.epl.geometry.Polygon   cutteeRemainder = (com.epl.geometry.Polygon)shape.GetGeometry(cutteeHandle);
                com.epl.geometry.MultiPath left            = new com.epl.geometry.Polygon();
                com.epl.geometry.MultiPath right           = new com.epl.geometry.Polygon();
                m_cuts.Clear();
                m_cuts.Add(left);
                m_cuts.Add(right);
                for (int icutIndex = 0; icutIndex < cutHandles.Size(); icutIndex++)
                {
                    com.epl.geometry.Geometry cutGeometry;
                    {
                        // intersection
                        com.epl.geometry.EditShape shapeIntersect = new com.epl.geometry.EditShape();
                        int geometryA = shapeIntersect.AddGeometry(cutteeRemainder);
                        int geometryB = shapeIntersect.AddGeometry(shape.GetGeometry(cutHandles.Get(icutIndex)));
                        topoOp.SetEditShape(shapeIntersect, m_progressTracker);
                        int intersectHandle = topoOp.Intersection(geometryA, geometryB);
                        cutGeometry = shapeIntersect.GetGeometry(intersectHandle);
                        if (cutGeometry.IsEmpty())
                        {
                            continue;
                        }
                        int side = shape.GetGeometryUserIndex(cutHandles.Get(icutIndex), sideIndex);
                        if (side == 2)
                        {
                            left.Add((com.epl.geometry.MultiPath)cutGeometry, false);
                        }
                        else
                        {
                            if (side == 1)
                            {
                                right.Add((com.epl.geometry.MultiPath)cutGeometry, false);
                            }
                            else
                            {
                                m_cuts.Add((com.epl.geometry.MultiPath)cutGeometry);
                            }
                        }
                    }
                    {
                        // Undefined
                        // difference
                        com.epl.geometry.EditShape shapeDifference = new com.epl.geometry.EditShape();
                        int geometryA = shapeDifference.AddGeometry(cutteeRemainder);
                        int geometryB = shapeDifference.AddGeometry(shape.GetGeometry(cutHandles.Get(icutIndex)));
                        topoOp.SetEditShape(shapeDifference, m_progressTracker);
                        cutteeRemainder = (com.epl.geometry.Polygon)shapeDifference.GetGeometry(topoOp.Difference(geometryA, geometryB));
                    }
                }
                if (!cutteeRemainder.IsEmpty() && cutHandles.Size() > 0)
                {
                    m_cuts.Add((com.epl.geometry.MultiPath)cutteeRemainder);
                }
                if (left.IsEmpty() && right.IsEmpty())
                {
                    m_cuts.Clear();
                }
            }
            finally
            {
                // no cuts
                topoOp.RemoveShape();
            }
        }
Пример #26
0
        /// <summary>Executes sort on the Bucket_sort.</summary>
        /// <remarks>
        /// Executes sort on the Bucket_sort. The result is fed into the indices
        /// array in the range between begin (inclusive) and end (exclusive). Uses
        /// user supplied sorter to execute sort on each bucket. Users either supply
        /// the sorter and use this method of Bucket_sort class, or use other methods
        /// to form the buckets and take care of bucket sorting themselves.
        /// </remarks>
        public void Sort(com.epl.geometry.AttributeStreamOfInt32 indices, int begin, int end, com.epl.geometry.ClassicSort sorter)
        {
            if (end - begin < 32)
            {
                sorter.UserSort(begin, end, indices);
                return;
            }
            bool b_fallback = true;

            try
            {
                double miny = com.epl.geometry.NumberUtils.PositiveInf();
                double maxy = com.epl.geometry.NumberUtils.NegativeInf();
                for (int i = begin; i < end; i++)
                {
                    double y = sorter.GetValue(indices.Get(i));
                    if (y < miny)
                    {
                        miny = y;
                    }
                    if (y > maxy)
                    {
                        maxy = y;
                    }
                }
                if (Reset(end - begin, miny, maxy, end - begin))
                {
                    for (int i_1 = begin; i_1 < end; i_1++)
                    {
                        int    vertex = indices.Get(i_1);
                        double y      = sorter.GetValue(vertex);
                        int    bucket = GetBucket(y);
                        m_buckets.Set(bucket, m_buckets.Get(bucket) + 1);
                        // counting
                        // values
                        // in a
                        // bucket.
                        m_bucketed_indices.Write(i_1 - begin, vertex);
                    }
                    // Recalculate buckets to contain start positions of buckets.
                    int c = m_buckets.Get(0);
                    m_buckets.Set(0, 0);
                    for (int i_2 = 1, n = m_buckets.Size(); i_2 < n; i_2++)
                    {
                        int b = m_buckets.Get(i_2);
                        m_buckets.Set(i_2, c);
                        c += b;
                    }
                    for (int i_3 = begin; i_3 < end; i_3++)
                    {
                        int    vertex       = m_bucketed_indices.Read(i_3 - begin);
                        double y            = sorter.GetValue(vertex);
                        int    bucket       = GetBucket(y);
                        int    bucket_index = m_buckets.Get(bucket);
                        indices.Set(bucket_index + begin, vertex);
                        m_buckets.Set(bucket, bucket_index + 1);
                    }
                    b_fallback = false;
                }
            }
            catch (System.Exception)
            {
                m_buckets.Resize(0);
                m_bucketed_indices.Resize(0);
            }
            if (b_fallback)
            {
                sorter.UserSort(begin, end, indices);
                return;
            }
            int j = 0;

            for (int i_4 = 0, n = m_buckets.Size(); i_4 < n; i_4++)
            {
                int j0 = j;
                j = m_buckets.Get(i_4);
                if (j > j0)
                {
                    sorter.UserSort(begin + j0, begin + j, indices);
                }
            }
            System.Diagnostics.Debug.Assert((j == end));
            if (GetBucketCount() > 100)
            {
                // some heuristics to preserve memory
                m_buckets.Resize(0);
                m_bucketed_indices.Resize(0);
            }
        }
        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);
        }
 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(')');
 }
        internal static void LineStringText_(bool bRing, bool b_closed, 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.AttributeStreamOfInt32
                                             paths, int path, System.Text.StringBuilder @string)
        {
            int istart = paths.Read(path);
            int iend   = paths.Read(path + 1);

            if (istart == iend)
            {
                @string.Append("EMPTY");
                return;
            }
            @string.Append('(');
            if (bRing)
            {
                Point_(precision, b_export_zs, b_export_ms, zs, ms, position, istart, @string);
                @string.Append(", ");
                for (int point = iend - 1; point >= istart + 1; point--)
                {
                    Point_(precision, b_export_zs, b_export_ms, zs, ms, position, point, @string);
                    @string.Append(", ");
                }
                Point_(precision, b_export_zs, b_export_ms, zs, ms, position, istart, @string);
            }
            else
            {
                for (int point = istart; point < iend - 1; point++)
                {
                    Point_(precision, b_export_zs, b_export_ms, zs, ms, position, point, @string);
                    @string.Append(", ");
                }
                Point_(precision, b_export_zs, b_export_ms, zs, ms, position, iend - 1, @string);
                if (b_closed)
                {
                    @string.Append(", ");
                    Point_(precision, b_export_zs, b_export_ms, zs, ms, position, istart, @string);
                }
            }
            @string.Append(')');
        }