I solved it with (in Colab): from shapely import wkt and then for the geometry field: df['geometry'] = df['geometry'].apply(wkt.loads) gdf = gpd.GeoDataFrame(df, geometry='geometry', crs='EPSG:4326')
I get this below error when i try to generate the gdf = gdf.GeoDataFrame() could you help?? TypeError Traceback (most recent call last) c:\Users ame pc1\Downloads\Building footprints\building_footprint.ipynb Cell 3 in () ----> 1 gdf = gpd.GeoDataFrame(df, geometry='geometry', crs='EPSG:4326') 2 gdf.head() File c:\Program Files\Python310\lib\site-packages\geopandas\geodataframe.py:191, in GeoDataFrame.__init__(self, data, geometry, crs, *args, **kwargs) 183 if ( 184 hasattr(geometry, "crs") 185 and geometry.crs 186 and crs 187 and not geometry.crs == crs 188 ): 189 raise ValueError(crs_mismatch_error) --> 191 self.set_geometry(geometry, inplace=True, crs=crs) 193 if geometry is None and crs: 194 raise ValueError( 195 "Assigning CRS to a GeoDataFrame without a geometry column is not " 196 "supported. Supply geometry using the 'geometry=' keyword argument, " 197 "or by providing a DataFrame with column name 'geometry'", 198 ) File c:\Program Files\Python310\lib\site-packages\geopandas\geodataframe.py:348, in GeoDataFrame.set_geometry(self, col, drop, inplace, crs) 345 level.crs = crs 347 # Check that we are using a listlike of geometries ... --> 148 raise TypeError("Input must be valid geometry objects: {0}".format(geom)) 150 if compat.USE_PYGEOS: 151 return np.array(out, dtype=object) TypeError: Input must be valid geometry objects: POLYGON((87.7185491791352 22.5667828312016, 87.7184590804737 22.5667864311825, 87.7184519272495 22.5666320082646, 87.7185420258111 22.5666284082901, 87.7185491791352 22.5667828312016)) Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
@@geodev It worked, I could generate the shp files... it seems the polygons are in geodjango and we need to convert them in shapely format. after df = pd.read_csv(r"CSV file location") df.head() Need to use : from shapely import wkt from shapely.wkt import loads df['geometry'] = df['geometry'].apply(wkt.loads)
Very excellent explanation, I really appreciate your help. Thank you!
Glad you liked it. Thanks❤️
great sharing. thank you
Thanks for visiting
the gdf = gpd.GeoDataFrame(df,geometry='geometry',crs='EPSG:4326')
gdf.head()
is error. it said TypeError: Input must be valid geometry objects
Have you checked the code given in video description? Can you try to run that notebook.
I solved it with (in Colab):
from shapely import wkt
and then for the geometry field:
df['geometry'] = df['geometry'].apply(wkt.loads)
gdf = gpd.GeoDataFrame(df, geometry='geometry', crs='EPSG:4326')
That cool Mr, thank you \m/
Glad you liked it!
What properties / variables the shapefile contain?
It is possible to do the process in JupyterLab following the same steps, or it is necessary to do it in Visual Studio, thanks.
It can be done in both software.
hi. can we get data for 2000, 2010 also? if so, then how? Also, this is showing data of which particular year?
hi! did you able to find data from the past years? also needing it :(
@@allisonmadrigal472 no I didn't get data for past years.
@@SonaSharma-n6l even in different sources? huhu I also need data from 2016 to now
@@allisonmadrigal472 yes. if u get any data, drop reply to the comment
I can't run the first line, it said ModuleNotFoundError: No module named 'pandas'
You need to install the required libraries with following command;
pip install pandas
pip install geopandas
etc
whats the dasboard view in the minute 6? phython isn't it?
It is python notebook!
I ran the code in Jupyter Notebook, Anaconda, and It didn't work, What python notebook do you use?@@geodev
Sir i can download the data of Pakistan's.. how ita possible
Yes you can. Just download the data from Pakistan tile and process it as explained in video
@@geodev thanks for the help sir.. 😊💖
how to do this if i do not know programming
You can download csv and load it in Qgis. But there will be a memory issue for larger dataset.
@@geodev i tried
import geopandas as gps
import pandas as pd
from shapely.geometry import polygon
data = pd.read_csv('D:\buildings.csv')
gdf = gpd.GeoDataFrame(data, geometry=gpd.points_from_xy(data['longitude'], data['latitude']))
gdf.crs = 'EPSG:32244'
bbox = Polygon([(77.2770, 28.4988), (77.2740, 28.4988), (77.2740, 28.5984), (77.2770, 28.5984)])
cropped_gdf = gdf.cx[77.2770:77.2740, 28.4988:28.5984]
cropped_gdf.to_csv('crop_file.csv', index=False)
but error message I am getting is
OSError: [Errno 22] Invalid argument: 'D:\x08uildings.csv'
@@geodev I tried but the result is showing as Point data. I am not able to get Polygons. Can you please give the solution?
@@geodev I imported in QGIS as text separated values, and saved into gpkg, it takes 20min each step, but it was done without problems
how do you extract the building footprint from csv to polygon .shp sir? i need your guidance
I have shown the process in this tutorial!
I get this below error when i try to generate the gdf = gdf.GeoDataFrame() could you help??
TypeError Traceback (most recent call last)
c:\Users
ame pc1\Downloads\Building footprints\building_footprint.ipynb Cell 3 in ()
----> 1 gdf = gpd.GeoDataFrame(df, geometry='geometry', crs='EPSG:4326')
2 gdf.head()
File c:\Program Files\Python310\lib\site-packages\geopandas\geodataframe.py:191, in GeoDataFrame.__init__(self, data, geometry, crs, *args, **kwargs)
183 if (
184 hasattr(geometry, "crs")
185 and geometry.crs
186 and crs
187 and not geometry.crs == crs
188 ):
189 raise ValueError(crs_mismatch_error)
--> 191 self.set_geometry(geometry, inplace=True, crs=crs)
193 if geometry is None and crs:
194 raise ValueError(
195 "Assigning CRS to a GeoDataFrame without a geometry column is not "
196 "supported. Supply geometry using the 'geometry=' keyword argument, "
197 "or by providing a DataFrame with column name 'geometry'",
198 )
File c:\Program Files\Python310\lib\site-packages\geopandas\geodataframe.py:348, in GeoDataFrame.set_geometry(self, col, drop, inplace, crs)
345 level.crs = crs
347 # Check that we are using a listlike of geometries
...
--> 148 raise TypeError("Input must be valid geometry objects: {0}".format(geom))
150 if compat.USE_PYGEOS:
151 return np.array(out, dtype=object)
TypeError: Input must be valid geometry objects: POLYGON((87.7185491791352 22.5667828312016, 87.7184590804737 22.5667864311825, 87.7184519272495 22.5666320082646, 87.7185420258111 22.5666284082901, 87.7185491791352 22.5667828312016))
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
Which version of geopandas are you using? Make sure you have used the latest version!
@@geodev its geopandas-0.13.2
@@geodev It worked, I could generate the shp files... it seems the polygons are in geodjango and we need to convert them in shapely format.
after
df = pd.read_csv(r"CSV file location")
df.head()
Need to use :
from shapely import wkt
from shapely.wkt import loads
df['geometry'] = df['geometry'].apply(wkt.loads)
@@shreyasbharule8346 thank you. i got stuck here too