Esempio n. 1
0
        // Mirrors wkt
        private static void ExportPolygonToGeoJson_(int export_flags, com.epl.geometry.Polygon polygon, com.epl.geometry.JsonWriter json_writer)
        {
            com.epl.geometry.MultiPathImpl polygon_impl = (com.epl.geometry.MultiPathImpl)(polygon._getImpl());
            if ((export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportFailIfNotSimple) != 0)
            {
                int simple = polygon_impl.GetIsSimple(0.0);
                if (simple != com.epl.geometry.MultiVertexGeometryImpl.GeometryXSimple.Strong)
                {
                    throw new com.epl.geometry.GeometryException("corrupted geometry");
                }
            }
            int point_count   = polygon.GetPointCount();
            int polygon_count = polygon_impl.GetOGCPolygonCount();

            if (point_count > 0 && polygon_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 = polygon_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportStripZs) == 0;
            bool b_export_ms = polygon_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");
            }
            int path_count = 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)polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
                path_flags = polygon_impl.GetPathFlagsStreamRef();
                paths      = polygon_impl.GetPathStreamRef();
                path_count = polygon_impl.GetPathCount();
                if (b_export_zs)
                {
                    if (polygon_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z))
                    {
                        zs = (com.epl.geometry.AttributeStreamOfDbl)polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
                    }
                }
                if (b_export_ms)
                {
                    if (polygon_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M))
                    {
                        ms = (com.epl.geometry.AttributeStreamOfDbl)polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M);
                    }
                }
            }
            if ((export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportPreferMultiGeometry) == 0 && polygon_count <= 1)
            {
                PolygonTaggedText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, paths, path_count, json_writer);
            }
            else
            {
                MultiPolygonTaggedText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, polygon_count, path_count, json_writer);
            }
        }
        internal static void ExportPolygonToWkt(int export_flags, com.epl.geometry.Polygon polygon, System.Text.StringBuilder @string)
        {
            com.epl.geometry.MultiPathImpl polygon_impl = (com.epl.geometry.MultiPathImpl)polygon._getImpl();
            if ((export_flags & com.epl.geometry.WktExportFlags.wktExportFailIfNotSimple) != 0)
            {
                int simple = polygon_impl.GetIsSimple(0.0);
                if (simple != com.epl.geometry.MultiVertexGeometryImpl.GeometryXSimple.Strong)
                {
                    throw new com.epl.geometry.GeometryException("corrupted geometry");
                }
            }
            int point_count   = polygon.GetPointCount();
            int polygon_count = polygon_impl.GetOGCPolygonCount();

            if (point_count > 0 && polygon_count == 0)
            {
                throw new com.epl.geometry.GeometryException("corrupted geometry");
            }
            int  precision   = 17 - (7 & (export_flags >> 13));
            bool b_export_zs = polygon_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (export_flags & com.epl.geometry.WktExportFlags.wktExportStripZs) == 0;
            bool b_export_ms = polygon_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (export_flags & com.epl.geometry.WktExportFlags.wktExportStripMs) == 0;
            int  path_count  = 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)(polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION));
                path_flags = polygon_impl.GetPathFlagsStreamRef();
                paths      = polygon_impl.GetPathStreamRef();
                path_count = polygon_impl.GetPathCount();
                if (b_export_zs)
                {
                    if (polygon_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z))
                    {
                        zs = (com.epl.geometry.AttributeStreamOfDbl)polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
                    }
                }
                if (b_export_ms)
                {
                    if (polygon_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M))
                    {
                        ms = (com.epl.geometry.AttributeStreamOfDbl)polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M);
                    }
                }
            }
            if ((export_flags & com.epl.geometry.WktExportFlags.wktExportPolygon) != 0)
            {
                if (polygon_count > 1)
                {
                    throw new System.ArgumentException("Cannot export a Polygon with specified export flags: " + export_flags);
                }
                PolygonTaggedText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, path_count, @string);
            }
            else
            {
                MultiPolygonTaggedText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, polygon_count, path_count, @string);
            }
        }
Esempio n. 3
0
 internal PairwiseIntersectorImpl(com.epl.geometry.MultiPathImpl multi_path_impl_a, com.epl.geometry.MultiPathImpl multi_path_impl_b, double tolerance, bool b_paths)
 {
     m_multi_path_impl_a = multi_path_impl_a;
     m_multi_path_impl_b = multi_path_impl_b;
     m_b_paths           = b_paths;
     m_path_index        = -1;
     m_b_quad_tree       = false;
     com.epl.geometry.GeometryAccelerators geometry_accelerators_a = multi_path_impl_a._getAccelerators();
     if (geometry_accelerators_a != null)
     {
         com.epl.geometry.QuadTreeImpl qtree_a = (!b_paths ? geometry_accelerators_a.GetQuadTree() : geometry_accelerators_a.GetQuadTreeForPaths());
         if (qtree_a != null)
         {
             m_b_done          = false;
             m_tolerance       = tolerance;
             m_quad_tree       = qtree_a;
             m_qt_iter         = m_quad_tree.GetIterator();
             m_b_quad_tree     = true;
             m_b_swap_elements = true;
             m_function        = com.epl.geometry.PairwiseIntersectorImpl.State.nextPath;
             if (!b_paths)
             {
                 m_seg_iter = multi_path_impl_b.QuerySegmentIterator();
             }
             else
             {
                 m_path_index = multi_path_impl_b.GetPathCount();
             }
         }
     }
     // we will iterate backwards until we hit -1
     if (!m_b_quad_tree)
     {
         com.epl.geometry.GeometryAccelerators geometry_accelerators_b = multi_path_impl_b._getAccelerators();
         if (geometry_accelerators_b != null)
         {
             com.epl.geometry.QuadTreeImpl qtree_b = (!b_paths ? geometry_accelerators_b.GetQuadTree() : geometry_accelerators_b.GetQuadTreeForPaths());
             if (qtree_b != null)
             {
                 m_b_done          = false;
                 m_tolerance       = tolerance;
                 m_quad_tree       = qtree_b;
                 m_qt_iter         = m_quad_tree.GetIterator();
                 m_b_quad_tree     = true;
                 m_b_swap_elements = false;
                 m_function        = com.epl.geometry.PairwiseIntersectorImpl.State.nextPath;
                 if (!b_paths)
                 {
                     m_seg_iter = multi_path_impl_a.QuerySegmentIterator();
                 }
                 else
                 {
                     m_path_index = multi_path_impl_a.GetPathCount();
                 }
             }
         }
     }
     // we will iterate backwards until we hit -1
     if (!m_b_quad_tree)
     {
         if (!b_paths)
         {
             m_intersector = com.epl.geometry.InternalUtils.GetEnvelope2DIntersector(multi_path_impl_a, multi_path_impl_b, tolerance);
         }
         else
         {
             bool b_simple_a = multi_path_impl_a.GetIsSimple(0.0) >= 1;
             bool b_simple_b = multi_path_impl_b.GetIsSimple(0.0) >= 1;
             m_intersector = com.epl.geometry.InternalUtils.GetEnvelope2DIntersectorForParts(multi_path_impl_a, multi_path_impl_b, tolerance, b_simple_a, b_simple_b);
         }
     }
 }