MCPcopy Create free account
hub / github.com/PDAL/PDAL / update

Method update

pdal/Geometry.cpp:125–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123
124
125void Geometry::update(const std::string& wkt_or_json)
126{
127 bool isJson = (wkt_or_json.find("{") != wkt_or_json.npos) ||
128 (wkt_or_json.find("}") != wkt_or_json.npos);
129
130 bool maybeWkt = (wkt_or_json.find("(") != wkt_or_json.npos) ||
131 (wkt_or_json.find(")") != wkt_or_json.npos);
132
133 // first byte is 00 or 01
134 bool maybeWkb = (wkt_or_json[0] == 0 || wkt_or_json[0] == 1);
135
136 OGRGeometry *newGeom (nullptr);
137 std::string srs;
138
139 if (maybeWkb)
140 {
141 // assume WKB
142 newGeom = gdal::createFromWkb(wkt_or_json, srs);
143 if (!newGeom)
144 throw pdal_error("Unable to create geometry from input WKB");
145
146 if (!newGeom->getSpatialReference() && srs.size())
147 newGeom->assignSpatialReference(
148 new OGRSpatialReference(SpatialReference(srs).getWKT().data()));
149
150 }
151 else if (maybeWkt)
152 {
153 newGeom = gdal::createFromWkt(wkt_or_json, srs);
154 if (!newGeom)
155 throw pdal_error("Unable to create geometry from input WKT");
156
157 if (!newGeom->getSpatialReference() && srs.size())
158 newGeom->assignSpatialReference(
159 new OGRSpatialReference(SpatialReference(srs).getWKT().data()));
160 }
161 else if (isJson)
162 {
163 // createFromGeoJson may set the geometry's SRS for us
164 // because GeoJSON is 4326. If the user provided a 'srs'
165 // node, we're going to override with that, however
166 newGeom = gdal::createFromGeoJson(wkt_or_json, srs);
167 if (!newGeom)
168 throw pdal_error("Unable to create geometry from input GeoJSON");
169
170 if (srs.size())
171 newGeom->assignSpatialReference(
172 new OGRSpatialReference(SpatialReference(srs).getWKT().data()));
173 }
174 if (!newGeom)
175 throw pdal_error("Unable to create geometry from unknown input string.");
176
177 m_geom.reset(newGeom);
178 modified();
179}
180
181
182Geometry& Geometry::operator=(const Geometry& input)

Callers 4

TESTFunction · 0.45
FilterFactoryMethod · 0.45
Geometry.cppFile · 0.45

Calls 10

createFromWkbFunction · 0.85
createFromWktFunction · 0.85
createFromGeoJsonFunction · 0.85
getSpatialReferenceMethod · 0.80
getWKTMethod · 0.80
SpatialReferenceClass · 0.70
findMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
resetMethod · 0.45

Tested by 1

TESTFunction · 0.36