Пример #1
0
        public override object?ParseLiteral(IValueNode literal)
        {
            if (literal is NullValueNode)
            {
                return(null);
            }

            if (!(literal is ObjectValueNode obj) || obj.Fields.Count < 2)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            (int typeIndex, int coordinateIndex, int crsIndex)indices =
                ParseLiteralHelper.GetFieldIndices(obj,
                                                   _typeFieldName,
                                                   _coordinatesFieldName,
                                                   _crsFieldName);

            if (indices.typeIndex == -1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var type = (GeoJSONGeometryType)
                       _typeField.Type.ParseLiteral(obj.Fields[indices.typeIndex].Value);

            if (type != _geometryType || indices.coordinateIndex == -1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var coordinates = (IList <Coordinate>)
                              _coordinatesField.Type.ParseLiteral(obj.Fields[indices.coordinateIndex].Value);

            if (coordinates.Count < 1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var pointCount = coordinates.Count;
            var points     = new Point[pointCount];

            for (var i = 0; i < pointCount; i++)
            {
                points[i] = new Point(coordinates[i]);
            }

            if (indices.crsIndex == -1)
            {
                return(new MultiPoint(points));
            }

            var             srid    = (int)_crsField.Type.ParseLiteral(obj.Fields[indices.crsIndex].Value);
            GeometryFactory factory = NtsGeometryServices.Instance.CreateGeometryFactory(srid);

            return(factory.CreateMultiPoint(points));
        }
Пример #2
0
        public override object?ParseLiteral(IValueNode literal)
        {
            if (literal is NullValueNode)
            {
                return(null);
            }

            if (!(literal is ObjectValueNode obj))
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            (int typeIndex, int coordinateIndex, int crsIndex)indices =
                ParseLiteralHelper.GetFieldIndices(obj,
                                                   _typeFieldName,
                                                   _coordinatesFieldName,
                                                   _crsFieldName);

            if (indices.typeIndex == -1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var type = (GeoJSONGeometryType)
                       _typeField.Type.ParseLiteral(obj.Fields[indices.typeIndex].Value);

            if (type != _geometryType || indices.coordinateIndex == -1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var coordinates = (IList <Coordinate>)
                              _coordinatesField.Type.ParseLiteral(obj.Fields[indices.coordinateIndex].Value);

            if (coordinates.Count < 4)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var coords = new Coordinate[coordinates.Count];

            coordinates.CopyTo(coords, 0);

            var ring = new LinearRing(coords);

            if (indices.crsIndex == -1)
            {
                return(new Polygon(ring));
            }

            var srid = (int)_crsField.Type.ParseLiteral(obj.Fields[indices.crsIndex].Value);

            GeometryFactory factory = NtsGeometryServices.Instance.CreateGeometryFactory(srid);

            return(factory.CreatePolygon(ring));
        }
Пример #3
0
        public override object?ParseLiteral(IValueNode literal)
        {
            if (literal is NullValueNode)
            {
                return(null);
            }

            if (!(literal is ObjectValueNode obj))
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            (int typeIndex, int coordinateIndex, int crsIndex)indices =
                ParseLiteralHelper.GetFieldIndices(
                    obj,
                    _typeFieldName,
                    _coordinatesFieldName,
                    _crsFieldName);

            if (indices.typeIndex == -1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var type = (GeoJSONGeometryType)
                       _typeField.Type.ParseLiteral(obj.Fields[indices.typeIndex].Value);

            if (type != _geometryType || indices.coordinateIndex == -1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var parts = (List <List <Coordinate> >)
                        _coordinatesField.Type.ParseLiteral(obj.Fields[indices.coordinateIndex].Value);

            if (parts.Count < 1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var lineCount  = parts.Count;
            var geometries = new LineString[lineCount];

            for (var i = 0; i < lineCount; i++)
            {
                var pointCount  = parts[i].Count;
                var coordinates = new Coordinate[pointCount];

                for (var j = 0; j < pointCount; j++)
                {
                    coordinates[j] = new Coordinate(parts[i][j]);
                }

                geometries[i] = new LineString(coordinates);
            }

            if (indices.crsIndex == -1)
            {
                return(new MultiLineString(geometries));
            }

            var srid = (int)_crsField.Type.ParseLiteral(obj.Fields[indices.crsIndex].Value);

            GeometryFactory factory = NtsGeometryServices.Instance.CreateGeometryFactory(srid);

            return(factory.CreateMultiLineString(geometries));
        }