How do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I'm new to GIS and having a basic beginner problem. I've got data in the form of a geopackage .gpkg
from GADM.org. I can read in and use the data without problem using Geopandas (via built-in Fiona).
I've added and deleted some columns to the data, and changed some column names to ones more intuitive to me (for ease of later use and consistency across files). Minor edits.
Now I want to export the data to a file format that is easy to later read into Python as a GeoPandas dataframe. However, whenever I try
CityShapeFile.to_file('CityShapeFile_edited.gpkg',encoding='utf-8')
No matter which format I choose (e.g. gpkg, json, shp, ...) I don't get a single file, but rather a folder with 5 files: *.cpg
, *.dbf
, *.prj
, *.shp
, and *.shx
. I'm sure those files together contain all the data I need, but in order to read the data back into Python I really need it in one file (as far as I know). Considering the original data I downloaded is in a single gpkg file, this seems possible and probably normal, but how to do it?
I read in the Fiona manual that it can write zipped shapefiles, but I couldn't find any simple example of doing that with a GeoPandas dataframe, nor am I sure whether that can be read in correctly. So,
How do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?
python json geopandas fiona geopackage
New contributor
add a comment |Â
up vote
2
down vote
favorite
I'm new to GIS and having a basic beginner problem. I've got data in the form of a geopackage .gpkg
from GADM.org. I can read in and use the data without problem using Geopandas (via built-in Fiona).
I've added and deleted some columns to the data, and changed some column names to ones more intuitive to me (for ease of later use and consistency across files). Minor edits.
Now I want to export the data to a file format that is easy to later read into Python as a GeoPandas dataframe. However, whenever I try
CityShapeFile.to_file('CityShapeFile_edited.gpkg',encoding='utf-8')
No matter which format I choose (e.g. gpkg, json, shp, ...) I don't get a single file, but rather a folder with 5 files: *.cpg
, *.dbf
, *.prj
, *.shp
, and *.shx
. I'm sure those files together contain all the data I need, but in order to read the data back into Python I really need it in one file (as far as I know). Considering the original data I downloaded is in a single gpkg file, this seems possible and probably normal, but how to do it?
I read in the Fiona manual that it can write zipped shapefiles, but I couldn't find any simple example of doing that with a GeoPandas dataframe, nor am I sure whether that can be read in correctly. So,
How do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?
python json geopandas fiona geopackage
New contributor
You can load a shapefile as a geodataframe, just read the .shp file. Check out the documentation for writing: geopandas.org/reference.html, there is a to_json() method that will write your gdf to a single json file. I believe you can add driver='GPKG' to you to_file() call to export a gpkg.
â Jon
2 hours ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm new to GIS and having a basic beginner problem. I've got data in the form of a geopackage .gpkg
from GADM.org. I can read in and use the data without problem using Geopandas (via built-in Fiona).
I've added and deleted some columns to the data, and changed some column names to ones more intuitive to me (for ease of later use and consistency across files). Minor edits.
Now I want to export the data to a file format that is easy to later read into Python as a GeoPandas dataframe. However, whenever I try
CityShapeFile.to_file('CityShapeFile_edited.gpkg',encoding='utf-8')
No matter which format I choose (e.g. gpkg, json, shp, ...) I don't get a single file, but rather a folder with 5 files: *.cpg
, *.dbf
, *.prj
, *.shp
, and *.shx
. I'm sure those files together contain all the data I need, but in order to read the data back into Python I really need it in one file (as far as I know). Considering the original data I downloaded is in a single gpkg file, this seems possible and probably normal, but how to do it?
I read in the Fiona manual that it can write zipped shapefiles, but I couldn't find any simple example of doing that with a GeoPandas dataframe, nor am I sure whether that can be read in correctly. So,
How do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?
python json geopandas fiona geopackage
New contributor
I'm new to GIS and having a basic beginner problem. I've got data in the form of a geopackage .gpkg
from GADM.org. I can read in and use the data without problem using Geopandas (via built-in Fiona).
I've added and deleted some columns to the data, and changed some column names to ones more intuitive to me (for ease of later use and consistency across files). Minor edits.
Now I want to export the data to a file format that is easy to later read into Python as a GeoPandas dataframe. However, whenever I try
CityShapeFile.to_file('CityShapeFile_edited.gpkg',encoding='utf-8')
No matter which format I choose (e.g. gpkg, json, shp, ...) I don't get a single file, but rather a folder with 5 files: *.cpg
, *.dbf
, *.prj
, *.shp
, and *.shx
. I'm sure those files together contain all the data I need, but in order to read the data back into Python I really need it in one file (as far as I know). Considering the original data I downloaded is in a single gpkg file, this seems possible and probably normal, but how to do it?
I read in the Fiona manual that it can write zipped shapefiles, but I couldn't find any simple example of doing that with a GeoPandas dataframe, nor am I sure whether that can be read in correctly. So,
How do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?
python json geopandas fiona geopackage
python json geopandas fiona geopackage
New contributor
New contributor
New contributor
asked 4 hours ago
Aaron Bramson
1134
1134
New contributor
New contributor
You can load a shapefile as a geodataframe, just read the .shp file. Check out the documentation for writing: geopandas.org/reference.html, there is a to_json() method that will write your gdf to a single json file. I believe you can add driver='GPKG' to you to_file() call to export a gpkg.
â Jon
2 hours ago
add a comment |Â
You can load a shapefile as a geodataframe, just read the .shp file. Check out the documentation for writing: geopandas.org/reference.html, there is a to_json() method that will write your gdf to a single json file. I believe you can add driver='GPKG' to you to_file() call to export a gpkg.
â Jon
2 hours ago
You can load a shapefile as a geodataframe, just read the .shp file. Check out the documentation for writing: geopandas.org/reference.html, there is a to_json() method that will write your gdf to a single json file. I believe you can add driver='GPKG' to you to_file() call to export a gpkg.
â Jon
2 hours ago
You can load a shapefile as a geodataframe, just read the .shp file. Check out the documentation for writing: geopandas.org/reference.html, there is a to_json() method that will write your gdf to a single json file. I believe you can add driver='GPKG' to you to_file() call to export a gpkg.
â Jon
2 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
To write to GeoJSON:
dataframe.to_file("output.json", driver="GeoJSON")
To write to GeoPackage:
dataframe.to_file("output.gpkg", driver="GPKG")
Documentation is here, though somewhat sparse.
This worked perfectly. I had no idea, and saw no previous examples, of specifying the driver when writing the file. On reflection I would expect that the packages would be clever enough to determine the driver from the file extension, but at least I now know the trick.
â Aaron Bramson
1 hour ago
The documentation is indeed a bit sparse .. Feel free to open an issue for that on github.com/geopandas/geopandas, or do a pull request to update!
â joris
9 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
To write to GeoJSON:
dataframe.to_file("output.json", driver="GeoJSON")
To write to GeoPackage:
dataframe.to_file("output.gpkg", driver="GPKG")
Documentation is here, though somewhat sparse.
This worked perfectly. I had no idea, and saw no previous examples, of specifying the driver when writing the file. On reflection I would expect that the packages would be clever enough to determine the driver from the file extension, but at least I now know the trick.
â Aaron Bramson
1 hour ago
The documentation is indeed a bit sparse .. Feel free to open an issue for that on github.com/geopandas/geopandas, or do a pull request to update!
â joris
9 mins ago
add a comment |Â
up vote
2
down vote
accepted
To write to GeoJSON:
dataframe.to_file("output.json", driver="GeoJSON")
To write to GeoPackage:
dataframe.to_file("output.gpkg", driver="GPKG")
Documentation is here, though somewhat sparse.
This worked perfectly. I had no idea, and saw no previous examples, of specifying the driver when writing the file. On reflection I would expect that the packages would be clever enough to determine the driver from the file extension, but at least I now know the trick.
â Aaron Bramson
1 hour ago
The documentation is indeed a bit sparse .. Feel free to open an issue for that on github.com/geopandas/geopandas, or do a pull request to update!
â joris
9 mins ago
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
To write to GeoJSON:
dataframe.to_file("output.json", driver="GeoJSON")
To write to GeoPackage:
dataframe.to_file("output.gpkg", driver="GPKG")
Documentation is here, though somewhat sparse.
To write to GeoJSON:
dataframe.to_file("output.json", driver="GeoJSON")
To write to GeoPackage:
dataframe.to_file("output.gpkg", driver="GPKG")
Documentation is here, though somewhat sparse.
answered 1 hour ago
toms
5,13411220
5,13411220
This worked perfectly. I had no idea, and saw no previous examples, of specifying the driver when writing the file. On reflection I would expect that the packages would be clever enough to determine the driver from the file extension, but at least I now know the trick.
â Aaron Bramson
1 hour ago
The documentation is indeed a bit sparse .. Feel free to open an issue for that on github.com/geopandas/geopandas, or do a pull request to update!
â joris
9 mins ago
add a comment |Â
This worked perfectly. I had no idea, and saw no previous examples, of specifying the driver when writing the file. On reflection I would expect that the packages would be clever enough to determine the driver from the file extension, but at least I now know the trick.
â Aaron Bramson
1 hour ago
The documentation is indeed a bit sparse .. Feel free to open an issue for that on github.com/geopandas/geopandas, or do a pull request to update!
â joris
9 mins ago
This worked perfectly. I had no idea, and saw no previous examples, of specifying the driver when writing the file. On reflection I would expect that the packages would be clever enough to determine the driver from the file extension, but at least I now know the trick.
â Aaron Bramson
1 hour ago
This worked perfectly. I had no idea, and saw no previous examples, of specifying the driver when writing the file. On reflection I would expect that the packages would be clever enough to determine the driver from the file extension, but at least I now know the trick.
â Aaron Bramson
1 hour ago
The documentation is indeed a bit sparse .. Feel free to open an issue for that on github.com/geopandas/geopandas, or do a pull request to update!
â joris
9 mins ago
The documentation is indeed a bit sparse .. Feel free to open an issue for that on github.com/geopandas/geopandas, or do a pull request to update!
â joris
9 mins ago
add a comment |Â
Aaron Bramson is a new contributor. Be nice, and check out our Code of Conduct.
Aaron Bramson is a new contributor. Be nice, and check out our Code of Conduct.
Aaron Bramson is a new contributor. Be nice, and check out our Code of Conduct.
Aaron Bramson is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f298530%2fhow-do-i-write-a-geopandas-dataframe-into-a-single-file-preferably-json-or-geop%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You can load a shapefile as a geodataframe, just read the .shp file. Check out the documentation for writing: geopandas.org/reference.html, there is a to_json() method that will write your gdf to a single json file. I believe you can add driver='GPKG' to you to_file() call to export a gpkg.
â Jon
2 hours ago