Example #1
0
        private void _fixOrphanVertices()
        {
            int pathCount = 0;

            // clean any path info
            for (int node = m_sortedVertices.GetFirst(m_sortedVertices.GetFirstList()); node != -1; node = m_sortedVertices.GetNext(node))
            {
                int vertex = m_sortedVertices.GetData(node);
                m_shape.SetPathToVertex_(vertex, -1);
            }
            int geometrySize = 0;

            for (int path = m_shape.GetFirstPath(m_geometry); path != -1;)
            {
                int first = m_shape.GetFirstVertex(path);
                if (first == -1 || m_shape.GetPathFromVertex(first) != -1)
                {
                    int p = path;
                    path = m_shape.GetNextPath(path);
                    m_shape.RemovePathOnly_(p);
                    continue;
                }
                m_shape.SetPathToVertex_(first, path);
                int pathSize = 1;
                for (int vertex = m_shape.GetNextVertex(first); vertex != first; vertex = m_shape.GetNextVertex(vertex))
                {
                    m_shape.SetPathToVertex_(vertex, path);
                    pathSize++;
                }
                m_shape.SetRingAreaValid_(path, false);
                m_shape.SetPathSize_(path, pathSize);
                m_shape.SetLastVertex_(path, m_shape.GetPrevVertex(first));
                geometrySize += pathSize;
                pathCount++;
                path = m_shape.GetNextPath(path);
            }
            // Some vertices do not belong to any path. We have to create new path
            // objects for those.
            // Produce new paths for the orphan vertices.
            for (int node_1 = m_sortedVertices.GetFirst(m_sortedVertices.GetFirstList()); node_1 != -1; node_1 = m_sortedVertices.GetNext(node_1))
            {
                int vertex = m_sortedVertices.GetData(node_1);
                if (m_shape.GetPathFromVertex(vertex) != -1)
                {
                    continue;
                }
                int path_1 = m_shape.InsertClosedPath_(m_geometry, -1, vertex, vertex, null);
                geometrySize += m_shape.GetPathSize(path_1);
                pathCount++;
            }
            m_shape.SetGeometryPathCount_(m_geometry, pathCount);
            m_shape.SetGeometryVertexCount_(m_geometry, geometrySize);
            int totalPointCount = 0;

            for (int geometry = m_shape.GetFirstGeometry(); geometry != -1; geometry = m_shape.GetNextGeometry(geometry))
            {
                totalPointCount += m_shape.GetPointCount(geometry);
            }
            m_shape.SetTotalPointCount_(totalPointCount);
        }
Example #2
0
        internal virtual bool FixRingOrientation_()
        {
            bool bFound = false;

            if (m_fixSelfTangency)
            {
                bFound = FixRingSelfTangency_();
            }
            if (m_shape.GetPathCount(m_geometry) == 1)
            {
                int    path = m_shape.GetFirstPath(m_geometry);
                double area = m_shape.GetRingArea(path);
                m_shape.SetExterior(path, true);
                if (area < 0)
                {
                    int first = m_shape.GetFirstVertex(path);
                    m_shape.ReverseRingInternal_(first);
                    m_shape.SetLastVertex_(path, m_shape.GetPrevVertex(first));
                    // fix
                    // last
                    // after
                    // the
                    // reverse
                    return(true);
                }
                return(false);
            }
            m_path_orientation_index = m_shape.CreatePathUserIndex();
            // used to
            // store
            // discovered
            // orientation
            // (3 -
            // extrior,
            // 2 -
            // interior)
            m_path_parentage_index = m_shape.CreatePathUserIndex();
            // used to
            // resolve OGC
            // order
            for (int path_1 = m_shape.GetFirstPath(m_geometry); path_1 != -1; path_1 = m_shape.GetNextPath(path_1))
            {
                m_shape.SetPathUserIndex(path_1, m_path_orientation_index, 0);
                m_shape.SetPathUserIndex(path_1, m_path_parentage_index, -1);
            }
            com.epl.geometry.AttributeStreamOfInt32 bunch = new com.epl.geometry.AttributeStreamOfInt32(0);
            m_y_scanline = com.epl.geometry.NumberUtils.TheNaN;
            com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
            m_unknown_ring_orientation_count = m_shape.GetPathCount(m_geometry);
            m_node_1_user_index = m_shape.CreateUserIndex();
            m_node_2_user_index = m_shape.CreateUserIndex();
            for (int ivertex = m_sorted_vertices.GetFirst(m_sorted_vertices.GetFirstList()); ivertex != -1; ivertex = m_sorted_vertices.GetNext(ivertex))
            {
                int vertex = m_sorted_vertices.GetData(ivertex);
                m_shape.GetXY(vertex, pt);
                if (pt.y != m_y_scanline && bunch.Size() != 0)
                {
                    bFound |= ProcessBunchForRingOrientationTest_(bunch);
                    m_sweep_comparator.Reset();
                    bunch.Clear(false);
                }
                bunch.Add(vertex);
                // all vertices that have same y are added to the
                // bunch
                m_y_scanline = pt.y;
                if (m_unknown_ring_orientation_count == 0)
                {
                    break;
                }
            }
            if (m_unknown_ring_orientation_count > 0)
            {
                bFound |= ProcessBunchForRingOrientationTest_(bunch);
                bunch.Clear(false);
            }
            m_shape.RemoveUserIndex(m_node_1_user_index);
            m_shape.RemoveUserIndex(m_node_2_user_index);
            // dbg_verify_ring_orientation_();//debug
            for (int path_2 = m_shape.GetFirstPath(m_geometry); path_2 != -1;)
            {
                if (m_shape.GetPathUserIndex(path_2, m_path_orientation_index) == 3)
                {
                    // exterior
                    m_shape.SetExterior(path_2, true);
                    int afterPath = path_2;
                    for (int nextHole = m_shape.GetPathUserIndex(path_2, m_path_parentage_index); nextHole != -1;)
                    {
                        int p = m_shape.GetPathUserIndex(nextHole, m_path_parentage_index);
                        m_shape.MovePath(m_geometry, m_shape.GetNextPath(afterPath), nextHole);
                        afterPath = nextHole;
                        nextHole  = p;
                    }
                    path_2 = m_shape.GetNextPath(afterPath);
                }
                else
                {
                    m_shape.SetExterior(path_2, false);
                    path_2 = m_shape.GetNextPath(path_2);
                }
            }
            m_shape.RemovePathUserIndex(m_path_orientation_index);
            m_shape.RemovePathUserIndex(m_path_parentage_index);
            return(bFound);
        }