Skip to content

Commit

Permalink
Added encoding and crs params for add_features_shapefile method
Browse files Browse the repository at this point in the history
Signed-off-by: Kharude, Sachin <sachin.kharude@here.com>
  • Loading branch information
Kharude, Sachin authored and omanges committed Aug 21, 2020
1 parent cc6efaa commit 72a5551
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/space/test_space_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def test_add_features_shapefile(empty_space):
"""Test uploading shapefile to the space."""
space = empty_space
shapefile = Path(__file__).parents[1] / "data" / "stations.zip"
space.add_features_shapefile(f"zip://{shapefile}")
space.add_features_shapefile(f"zip://{shapefile}", crs="EPSG:4326")
resp = space.search(params={"p.name": "Van Dorn Street"})
flist = list(resp)
assert flist[0]["geometry"]["coordinates"] == [
Expand Down
15 changes: 13 additions & 2 deletions xyzspaces/spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,12 @@ def isshared(self) -> bool:
return True if "shared" in self.info else False

def add_features_shapefile(
self, path: str, features_size: int = 2000, chunk_size: int = 1
self,
path: str,
features_size: int = 2000,
chunk_size: int = 1,
crs: str = None,
encoding: str = "utf-8",
):
"""Upload shapefile to the space.
Expand All @@ -893,14 +898,20 @@ def add_features_shapefile(
a time.
:param chunk_size: Number of chunks for each process to handle. The default value
is 1, for a large number of features please use `chunk_size` greater than 1.
:param crs: A string to represent Coordinate Reference System(CRS),
If you want to change CRS, please pass the value of desired CRS
Example: ``epsg:4326``.
:param encoding: A string to represent the type of encoding.
Example:
>>> from xyzspaces import XYZ
>>> xyz = XYZ(credentials="XYZ_TOKEN")
>>> space = xyz.spaces.from_id(space_id="existing-space-id")
>>> space.add_features_shapefile(path="shapefile.shp")
"""
gdf = gpd.read_file(path)
gdf = gpd.read_file(path, encoding=encoding)
if crs is not None:
gdf = gdf.to_crs(crs)
with tempfile.NamedTemporaryFile() as temp:
gdf.to_file(temp.name, driver="GeoJSON")
self.add_features_geojson(
Expand Down

0 comments on commit 72a5551

Please sign in to comment.