Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def from_wkt(s):
"""
Parse a Point geometry from a wkt string and return a new Point object.
"""
if not _HAS_GEOMET:
raise DriverException("Geomet is required to deserialize a wkt geometry.")
try:
geom = wkt.loads(s)
except ValueError:
raise ValueError("Invalid WKT geometry: '{0}'".format(s))
if geom['type'] != 'Point':
raise ValueError("Invalid WKT geometry type. Expected 'Point', got '{0}': '{1}'".format(geom['type'], s))
coords = geom['coordinates']
if len(coords) < 2:
x = y = _nan
else:
x = coords[0]
y = coords[1]
return Point(x=x, y=y)
"""
if _HASGEOMET == False and geom_format.lower() in ['wkt', 'geojson']:
raise ValueError(("The package `geomet` is required to work with "
"WKT and GeoJSON. Run `pip install geomet` to install."))
if isinstance(row, _Row):
row = row._values
values = None
flds = {fld.lower(): fld for fld in row.keys()}
if 'shape' in flds:
if isinstance(row[flds['shape']], dict) and geom_format.lower() == "esrijson":
row[flds['shape']] = self._gpheader + dumps(row[flds['shape']], False)
elif isinstance(row[flds['shape']], dict) and geom_format.lower() == "geojson":
row[flds['shape']] = self._gpheader + geometwkb.dumps(obj=row[flds['shape']])
elif isinstance(row[flds['shape']], str) and geom_format.lower() == "wkt":
gj = geometwkt.loads(row[flds['shape']])
row[flds['shape']] = self._gpheader + geometwkb.dumps(obj=gj)
elif isinstance(row[flds['shape']], (bytes, bytearray)):
if isinstance(row[flds['shape']], (bytearray)):
row[flds['shape']] = bytes(row[flds['shape']])
if len(row[flds['shape']]) > 2 and \
row[flds['shape']][:2] != b'GB':
row[flds['shape']] = self._gpheader + row[flds['shape']]
elif row[flds['shape']] is None:
row[flds['shape']] = self._gpheader + b'0x000000000000f87f'
else:
raise ValueError(("Shape column must be Esri JSON dictionary, "
"WKT, GeoJSON dictionary, or WKB (bytes)"))
if isinstance(row, dict):
keys = row.keys()
values = [list(row.values())]
elif isinstance(row, (list, tuple)):
def from_wkt(s):
"""
Parse a LineString geometry from a wkt string and return a new LineString object.
"""
if not _HAS_GEOMET:
raise DriverException("Geomet is required to deserialize a wkt geometry.")
try:
geom = wkt.loads(s)
except ValueError:
raise ValueError("Invalid WKT geometry: '{0}'".format(s))
if geom['type'] != 'LineString':
raise ValueError("Invalid WKT geometry type. Expected 'LineString', got '{0}': '{1}'".format(geom['type'], s))
geom['coordinates'] = list_contents_to_tuple(geom['coordinates'])
return LineString(coords=geom['coordinates'])