internal static int MultiPointText(com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, com.epl.geometry.WktParser wkt_parser)
        {
            // At start of MultiPointText
            int current_token = wkt_parser.CurrentToken();
            int point_count   = 0;

            if (current_token == com.epl.geometry.WktParser.WktToken.empty)
            {
                return(point_count);
            }
            current_token = wkt_parser.NextToken();
            while (current_token != com.epl.geometry.WktParser.WktToken.right_paren)
            {
                // At start of PointText
                point_count += PointText(zs, ms, position, wkt_parser);
                if (current_token == com.epl.geometry.WktParser.WktToken.left_paren || current_token == com.epl.geometry.WktParser.WktToken.empty)
                {
                    current_token = wkt_parser.NextToken();
                }
                else
                {
                    // ogc standard
                    current_token = wkt_parser.CurrentToken();
                }
            }
            // not ogc standard.
            // treat as
            // linestring
            return(point_count);
        }
        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 com.epl.geometry.Geometry PointTaggedText(int import_flags, com.epl.geometry.WktParser wkt_parser)
        {
            com.epl.geometry.Point point = new com.epl.geometry.Point();
            int current_token            = wkt_parser.NextToken();

            if (current_token == com.epl.geometry.WktParser.WktToken.attribute_z)
            {
                point.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                wkt_parser.NextToken();
            }
            else
            {
                if (current_token == com.epl.geometry.WktParser.WktToken.attribute_m)
                {
                    point.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                    wkt_parser.NextToken();
                }
                else
                {
                    if (current_token == com.epl.geometry.WktParser.WktToken.attribute_zm)
                    {
                        point.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                        point.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                        wkt_parser.NextToken();
                    }
                }
            }
            // At start of PointText
            current_token = wkt_parser.CurrentToken();
            if (current_token != com.epl.geometry.WktParser.WktToken.empty)
            {
                wkt_parser.NextToken();
                double x = wkt_parser.CurrentNumericLiteral();
                wkt_parser.NextToken();
                double y = wkt_parser.CurrentNumericLiteral();
                wkt_parser.NextToken();
                point.SetXY(x, y);
                if (wkt_parser.HasZs())
                {
                    double z = wkt_parser.CurrentNumericLiteral();
                    wkt_parser.NextToken();
                    point.SetZ(z);
                }
                if (wkt_parser.HasMs())
                {
                    double m = wkt_parser.CurrentNumericLiteral();
                    wkt_parser.NextToken();
                    point.SetM(m);
                }
            }
            return(point);
        }
 public override com.epl.geometry.OGCStructure ExecuteOGC(int import_flags, string wkt_string, com.epl.geometry.ProgressTracker progress_tracker)
 {
     System.Collections.Generic.List <com.epl.geometry.OGCStructure> stack = new System.Collections.Generic.List <com.epl.geometry.OGCStructure>(0);
     com.epl.geometry.WktParser    wkt_parser = new com.epl.geometry.WktParser(wkt_string);
     com.epl.geometry.OGCStructure root       = new com.epl.geometry.OGCStructure();
     root.m_structures = new System.Collections.Generic.List <com.epl.geometry.OGCStructure>(0);
     stack.Add(root);
     // add dummy root
     while (wkt_parser.NextToken() != com.epl.geometry.WktParser.WktToken.not_available)
     {
         int current_token = wkt_parser.CurrentToken();
         if (current_token == com.epl.geometry.WktParser.WktToken.right_paren)
         {
             stack.RemoveAt(stack.Count - 1);
             continue;
         }
         int ogc_type = current_token;
         com.epl.geometry.OGCStructure last = stack[stack.Count - 1];
         if (current_token == com.epl.geometry.WktParser.WktToken.geometrycollection)
         {
             current_token = wkt_parser.NextToken();
             if (current_token == com.epl.geometry.WktParser.WktToken.attribute_z || current_token == com.epl.geometry.WktParser.WktToken.attribute_m || current_token == com.epl.geometry.WktParser.WktToken.attribute_zm)
             {
                 wkt_parser.NextToken();
             }
             com.epl.geometry.OGCStructure next = new com.epl.geometry.OGCStructure();
             next.m_type       = ogc_type;
             next.m_structures = new System.Collections.Generic.List <com.epl.geometry.OGCStructure>(0);
             last.m_structures.Add(next);
             if (current_token != com.epl.geometry.WktParser.WktToken.empty)
             {
                 stack.Add(next);
             }
             continue;
         }
         com.epl.geometry.Geometry     geometry = ImportFromWkt(import_flags, com.epl.geometry.Geometry.Type.Unknown, wkt_parser);
         com.epl.geometry.OGCStructure leaf     = new com.epl.geometry.OGCStructure();
         leaf.m_type     = ogc_type;
         leaf.m_geometry = geometry;
         last.m_structures.Add(leaf);
     }
     return(root);
 }
        internal static int MultiPolygonText(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 MultiPolygonText
            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 PolygonText
                total_point_count = PolygonText(zs, ms, position, paths, path_flags, total_point_count, wkt_parser);
                current_token     = wkt_parser.NextToken();
            }
            return(total_point_count);
        }
        internal static int PointText(com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, com.epl.geometry.WktParser wkt_parser)
        {
            // At start of PointText
            int current_token = wkt_parser.CurrentToken();

            if (current_token == com.epl.geometry.WktParser.WktToken.empty)
            {
                return(0);
            }
            if (current_token == com.epl.geometry.WktParser.WktToken.left_paren)
            {
                wkt_parser.NextToken();
            }
            // ogc standard
            // 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 (zs != null)
            {
                z = wkt_parser.CurrentNumericLiteral();
                wkt_parser.NextToken();
            }
            if (ms != null)
            {
                m = wkt_parser.CurrentNumericLiteral();
                wkt_parser.NextToken();
            }
            AddToStreams(zs, ms, position, x, y, z, m);
            return(1);
        }
        internal static com.epl.geometry.Geometry ImportFromWkt(int import_flags, com.epl.geometry.Geometry.Type type, com.epl.geometry.WktParser wkt_parser)
        {
            int current_token = wkt_parser.CurrentToken();

            switch (current_token)
            {
            case com.epl.geometry.WktParser.WktToken.multipolygon:
            {
                if (type != com.epl.geometry.Geometry.Type.Polygon && type != com.epl.geometry.Geometry.Type.Unknown)
                {
                    throw new System.ArgumentException("invalid shapetype");
                }
                return(PolygonTaggedText(true, import_flags, wkt_parser));
            }

            case com.epl.geometry.WktParser.WktToken.multilinestring:
            {
                if (type != com.epl.geometry.Geometry.Type.Polyline && type != com.epl.geometry.Geometry.Type.Unknown)
                {
                    throw new System.ArgumentException("invalid shapetype");
                }
                return(LineStringTaggedText(true, import_flags, wkt_parser));
            }

            case com.epl.geometry.WktParser.WktToken.multipoint:
            {
                if (type != com.epl.geometry.Geometry.Type.MultiPoint && type != com.epl.geometry.Geometry.Type.Unknown)
                {
                    throw new System.ArgumentException("invalid shapetype");
                }
                return(MultiPointTaggedText(import_flags, wkt_parser));
            }

            case com.epl.geometry.WktParser.WktToken.polygon:
            {
                if (type != com.epl.geometry.Geometry.Type.Polygon && type != com.epl.geometry.Geometry.Type.Unknown)
                {
                    throw new System.ArgumentException("invalid shapetype");
                }
                return(PolygonTaggedText(false, import_flags, wkt_parser));
            }

            case com.epl.geometry.WktParser.WktToken.linestring:
            {
                if (type != com.epl.geometry.Geometry.Type.Polyline && type != com.epl.geometry.Geometry.Type.Unknown)
                {
                    throw new System.ArgumentException("invalid shapetype");
                }
                return(LineStringTaggedText(false, import_flags, wkt_parser));
            }

            case com.epl.geometry.WktParser.WktToken.point:
            {
                if (type != com.epl.geometry.Geometry.Type.Point && type != com.epl.geometry.Geometry.Type.Unknown)
                {
                    throw new System.ArgumentException("invalid shapetype");
                }
                return(PointTaggedText(import_flags, wkt_parser));
            }

            default:
            {
                break;
            }
            }
            // warning fix
            return(null);
        }
        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);
        }