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 virtual void TestReplaceNaNs() { com.epl.geometry.Envelope env = new com.epl.geometry.Envelope(); com.epl.geometry.Point pt = new com.epl.geometry.Point(); pt.SetXY(1, 2); pt.SetZ(double.NaN); pt.QueryEnvelope(env); pt.ReplaceNaNs(com.epl.geometry.VertexDescription.Semantics.Z, 5); NUnit.Framework.Assert.IsTrue(pt.Equals(new com.epl.geometry.Point(1, 2, 5))); NUnit.Framework.Assert.IsTrue(env.HasZ()); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).IsEmpty()); env.ReplaceNaNs(com.epl.geometry.VertexDescription.Semantics.Z, 5); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).Equals(new com.epl.geometry.Envelope1D(5, 5))); }
internal static com.epl.geometry.MapGeometry ImportFromJsonParser(int gt, com.epl.geometry.JsonReader parser) { com.epl.geometry.MapGeometry mp; try { if (!com.epl.geometry.JSONUtils.IsObjectStart(parser)) { return(null); } bool bFoundSpatial_reference = false; bool bFoundHasZ = false; bool bFoundHasM = false; bool bFoundPolygon = false; bool bFoundPolyline = false; bool bFoundMultiPoint = false; bool bFoundX = false; bool bFoundY = false; bool bFoundZ = false; bool bFoundM = false; bool bFoundXMin = false; bool bFoundYMin = false; bool bFoundXMax = false; bool bFoundYMax = false; bool bFoundZMin = false; bool bFoundZMax = false; bool bFoundMMin = false; bool bFoundMMax = false; double x = com.epl.geometry.NumberUtils.NaN(); double y = com.epl.geometry.NumberUtils.NaN(); double z = com.epl.geometry.NumberUtils.NaN(); double m = com.epl.geometry.NumberUtils.NaN(); double xmin = com.epl.geometry.NumberUtils.NaN(); double ymin = com.epl.geometry.NumberUtils.NaN(); double xmax = com.epl.geometry.NumberUtils.NaN(); double ymax = com.epl.geometry.NumberUtils.NaN(); double zmin = com.epl.geometry.NumberUtils.NaN(); double zmax = com.epl.geometry.NumberUtils.NaN(); double mmin = com.epl.geometry.NumberUtils.NaN(); double mmax = com.epl.geometry.NumberUtils.NaN(); bool bHasZ = false; bool bHasM = false; com.epl.geometry.AttributeStreamOfDbl @as = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0); com.epl.geometry.AttributeStreamOfDbl bs = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0); com.epl.geometry.Geometry geometry = null; com.epl.geometry.SpatialReference spatial_reference = null; while (parser.NextToken() != com.epl.geometry.JsonReader.Token.END_OBJECT) { string name = parser.CurrentString(); parser.NextToken(); if (!bFoundSpatial_reference && name.Equals("spatialReference")) { bFoundSpatial_reference = true; if (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.START_OBJECT) { spatial_reference = com.epl.geometry.SpatialReference.FromJson(parser); } else { if (parser.CurrentToken() != com.epl.geometry.JsonReader.Token.VALUE_NULL) { throw new com.epl.geometry.GeometryException("failed to parse spatial reference: object or null is expected"); } } } else { if (!bFoundHasZ && name.Equals("hasZ")) { bFoundHasZ = true; bHasZ = (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.VALUE_TRUE); } else { if (!bFoundHasM && name.Equals("hasM")) { bFoundHasM = true; bHasM = (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.VALUE_TRUE); } else { if (!bFoundPolygon && name.Equals("rings") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Polygon)) { bFoundPolygon = true; geometry = ImportFromJsonMultiPath(true, parser, @as, bs); continue; } else { if (!bFoundPolyline && name.Equals("paths") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Polyline)) { bFoundPolyline = true; geometry = ImportFromJsonMultiPath(false, parser, @as, bs); continue; } else { if (!bFoundMultiPoint && name.Equals("points") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.MultiPoint)) { bFoundMultiPoint = true; geometry = ImportFromJsonMultiPoint(parser, @as, bs); continue; } else { if (!bFoundX && name.Equals("x") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundX = true; x = ReadDouble(parser); } else { if (!bFoundY && name.Equals("y") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundY = true; y = ReadDouble(parser); } else { if (!bFoundZ && name.Equals("z") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundZ = true; z = ReadDouble(parser); } else { if (!bFoundM && name.Equals("m") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundM = true; m = ReadDouble(parser); } } } } } } } } } } if (!bFoundXMin && name.Equals("xmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundXMin = true; xmin = ReadDouble(parser); } else { if (!bFoundYMin && name.Equals("ymin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundYMin = true; ymin = ReadDouble(parser); } else { if (!bFoundMMin && name.Equals("mmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundMMin = true; mmin = ReadDouble(parser); } else { if (!bFoundZMin && name.Equals("zmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundZMin = true; zmin = ReadDouble(parser); } else { if (!bFoundXMax && name.Equals("xmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundXMax = true; xmax = ReadDouble(parser); } else { if (!bFoundYMax && name.Equals("ymax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundYMax = true; ymax = ReadDouble(parser); } else { if (!bFoundMMax && name.Equals("mmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundMMax = true; mmax = ReadDouble(parser); } else { if (!bFoundZMax && name.Equals("zmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundZMax = true; zmax = ReadDouble(parser); } else { Windup(parser); } } } } } } } } } if (bFoundPolygon || bFoundPolyline || bFoundMultiPoint) { System.Diagnostics.Debug.Assert((geometry != null)); com.epl.geometry.MultiVertexGeometryImpl mvImpl = (com.epl.geometry.MultiVertexGeometryImpl)geometry._getImpl(); com.epl.geometry.AttributeStreamBase zs = null; com.epl.geometry.AttributeStreamBase ms = null; if (bHasZ) { geometry.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z); zs = @as; } if (bHasM) { geometry.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); ms = !bHasZ ? @as : bs; } if (bHasZ && zs != null) { mvImpl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z, zs); } if (bHasM && ms != null) { mvImpl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M, ms); } mvImpl.NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyAll); } else { if (bFoundX || bFoundY || bFoundY || bFoundZ) { if (com.epl.geometry.NumberUtils.IsNaN(y)) { x = com.epl.geometry.NumberUtils.NaN(); } com.epl.geometry.Point p = new com.epl.geometry.Point(x, y); if (bFoundZ) { p.SetZ(z); } if (bFoundM) { p.SetM(m); } geometry = p; } else { if (bFoundXMin || bFoundYMin || bFoundXMax || bFoundYMax || bFoundZMin || bFoundZMax || bFoundMMin || bFoundMMax) { if (com.epl.geometry.NumberUtils.IsNaN(ymin) || com.epl.geometry.NumberUtils.IsNaN(xmax) || com.epl.geometry.NumberUtils.IsNaN(ymax)) { xmin = com.epl.geometry.NumberUtils.NaN(); } com.epl.geometry.Envelope e = new com.epl.geometry.Envelope(xmin, ymin, xmax, ymax); if (bFoundZMin && bFoundZMax) { e.SetInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0, zmin, zmax); } if (bFoundMMin && bFoundMMax) { e.SetInterval(com.epl.geometry.VertexDescription.Semantics.M, 0, mmin, mmax); } geometry = e; } } } mp = new com.epl.geometry.MapGeometry(geometry, spatial_reference); } catch (System.Exception) { return(null); } return(mp); }