How to save the fatures from Web Feature Service as a shapefile in python? - gis

0
I have a WFS running on URL that is mentioned in the code below. i want to get all the features available in the service as a shapefile so i can open it and visualize it in QGIS or any other GIS software. The servies provides the ability to download the shapefile as can be viewed here :
https://www.geoseaportal.de/wss/service/Site_Development_Plan_2020/guest?SERVICE=WFS&REQUEST=GetCapabilities&VERSION=2.0.0
I have tried the below code to fetch the data and save as a shapefile but it just creates an empty point shapefile which is not correct. How can i download it correctly?
from owslib.wfs import WebFeatureService
eaWFS = WebFeatureService(url='https://www.geoseaportal.de/wss/service/Site_Development_Plan_2020/guest?SERVICE=WFS', version='2.0.0')
floodData = eaWFS.getfeature(typename='Site_Development_Plan_2020:All', bbox=(419000,419000,421000,421000), outputFormat='SHAPE-ZIP')
out = open('C:\\Users\Chaudhr1\\arcgis\DATA.zip', 'wb')
out.write(floodData.read())
out.close()

Related

Fetch Folder from drive for Google Colab

I'm trying to run a deep learning model in jupyter notebook and its taking forever and also karnel dies during training . So i'm trying to run it on Google Colab . I've learned some basics that are available on the internet but its not helping me at all . The model gets it dataset from a module ,
this link https://github.com/awslabs/handwritten-text-recognition-for-apache-mxnet/blob/master/ocr/utils/iam_dataset.py has the module that extract and preprocess dataset for trining from local computer. I've uploaded the dataset in Gdrive now i want to change the path so that this module finds that 'dataset' folder . I've been stuck on it for 5 days and now i'm clueless .
I will suggest you not to load the dataset from GDrive to colab directly. It increases the dataset loading time.
Google Colab provides some local storage for your work(around 70 GB) that is shown on the upper-right corner below the RAM bar. Bring your dataset to that storage. This is how you can do it:-
import zipfile
from google.colab import drive
zip_ref = zipfile.ZipFile("/content/drive/My Drive/dataset.zip", 'r')
zip_ref.extractall("/content/")
zip_ref.close()
Please note that your entire dataset should be zipped.
It will be more than 20 times faster than the method you are trying...
Format of zipfile.ZipFile() function above:-
zip_ref = zipfile.ZipFile("/content/drive/Zip file location in GDrive", 'r')
If you click the folder icon in the left side in colab interface you should see your dataset there.
You can then access your dataset using the filepath='/content/dataset'

How to convert longitude and latitude data into shapefiles for NetLogo

I have some longitude and latitude data and would like to load them into NetLogo for modeling. I used QGIS to load and visualize the data successfully. Then I exported the data as shapefiles (.shp) format, and there are several other files being exported togeter with postfix .shx, .dbf, .qpj, .prj, and .cpg.
But when I tried to load the data in NetLogo as
extensions [ gis ]
globals [ elevation ]
to load
clear-all
set elevation gis:load-dataset "MyDir/XXX.shp"
gis:set-world-envelope gis:envelope-of elevation
end
it reported an error saying "Extension exception: only GEOGCS and PROJCS are supported"
I searched the error online and think maybe it is because the file I exported from QGIS is not supported by NetLogo. But I know nothing about GIS data, so have no idea how to fix this problem.
I compared my .prj file with the example file of NetLogo GIS extension, googled the difference, and found out the solution, which is as followed.
In the QGIS, click Project and select Properties. There is a CRS tag on the left. Open it and one can find a "Coordinate reference systems of the world" window, inside which click the first class named Geographic Coordinate Systems, and choose the one named GCS_WGS_1984_XX.
Click OK and go back to the main panel. Right click your layer and set the layer's CRS. Choose the GCS_WGS_1984_XX one. Now export the layer and it can be loaded by NetLogo successfully.

How to embed a map into Netlogo using GIS extension?

The format of the map imported should be preferably ".shp" file.Also please tell how to create such a file. I have tried KML but it didn't work.
Yes, vectors need to be .shp to be imported. You can create vector files in most GIS programs (ArcGIS, QGIS, etc) and export to .shp. Or there's online tools for converting KML to .shp (eg http://www.zonums.com/online/kml2shp.php)
Raster files need to be saved as .ASC or .GRD for use as a dataset in Netlogo.

How to add json data to geojson map, without going 'back' to shape files?

I'm trying to add data in json format to a geojson file. I realise that one way of doing this, is to transform the geojson file into a shape file, the data in an R object, and merge the two, as attempted here. However, I was wondering whether this is possible without switching 'back' to a shape file. Here's the code to obtain the geojson file and data file:
library(leafletR)
library(jsonlite)
# obtaining map
download.file("http://node-128.dev.socialhistoryservices.org/api/maps?year=1937",
destfile = paste0("testmap", ".json"))
map <- leaflet("./testmap.json")
map # displays map in browser
# obtaining data
testdata <-
fromJSON("http://node-128.dev.socialhistoryservices.org/api/data?code=TXCU")
Note: the 'key' in both files is 'amsterdam_code'
In case you are using node.js try extend-geojson-properties and if want to use on client side download index.js file from github project. See how to use in README of the project.
You can convert topojson to geojson features using topojson api. Then create a join map between geojson and json with common id.

Best way to overlay an ESRI shapefile on google maps?

What is the best way to overlay a shapefile in Google Maps?
After some reading suggests that, converting shapefile into KML and overlaying KML in Google map is an option. If that is the case, how do I convert a shapefile into KMLs?
I believe there would be a few open source tools available for this conversion. Can anyone point to a tool to covert a shapefile to KML without any loss of data?
I like using (open source and gui friendly) Quantum GIS to convert the shapefile to kml.
Google Maps API supports only a subset of the KML standard. One limitation is file size.
To reduce your file size, you can Quantum GIS's "simplify geometries" function. This "smooths" polygons.
Then you can select your layer and do a "save as kml" on it.
If you need to process a bunch of files, the process can be batched with Quantum GIS's ogr2ogr command from osgeo4w shell.
Finally, I recommend zipping your kml (with your favorite compression program) for reduced file size and saving it as kmz.
as of 12.03.2019 FusionTables is no more...
Import the Shapefile into Google FusionTables ( http://www.google.com/fusiontables ) using http://www.shpescape.com/ and from there you can use the data in a number of ways, eg. display it using GoogleMaps.
I would not use KML. Instead, use GeoJSON which you can natively consume in Google Maps API now. It is a newer feature that didn't exist from the original responses.
In any case, simply open the SHP file in Quantum GIS, and then you can output it in any format you like (KML, GeoJSON).
If you are using Google Maps for Work, I found a premium extension that handles loading shapefiles directly where you can just connect direct to the shapefile that you generate from ESRI. I did a search on the CMaps site and found this snippet which loaded US by state shapefile: https://gmapsplugin.net/cmapsanalytics/assets/shapes/usstates.shp
var cMap = new centigon.locationIntelligence.MapView();
cMap.key([your_api_key]);
cMap.layerNames(["Basic Shapes"]);
cMap.dbfKeys([['Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington','West Virginia','Wisconsin','Wyoming']]);
cMap.userShapeKeys([['Massachusetts','Minnesota','Montana','North Dakota','Hawaii','Idaho','Washington','Arizona','California','Colorado','Nevada','New Mexico','Oregon','Utah','Wyoming','Arkansas','Iowa','Kansas','Missouri','Nebraska','Oklahoma','South Dakota','Louisiana','Texas','Connecticut','New Hampshire','Rhode Island','Vermont','Alabama','Florida','Georgia','Mississippi','South Carolina','Illinois','Indiana','Kentucky','North Carolina','Ohio','Tennessee','Virginia','Wisconsin','West Virginia','Delaware','District of Columbia','Maryland','New Jersey','New York','Pennsylvania','Maine','Michigan','Alaska']]);
cMap.labels([['Massachusetts','Minnesota','Montana','North Dakota','Hawaii','Idaho','Washington','Arizona','California','Colorado','Nevada','New Mexico','Oregon','Utah','Wyoming','Arkansas','Iowa','Kansas','Missouri','Nebraska','Oklahoma','South Dakota','Louisiana','Texas','Connecticut','New Hampshire','Rhode Island','Vermont','Alabama','Florida','Georgia','Mississippi','South Carolina','Illinois','Indiana','Kentucky','North Carolina','Ohio','Tennessee','Virginia','Wisconsin','West Virginia','Delaware','District of Columbia','Maryland','New Jersey','New York','Pennsylvania','Maine','Michigan','Alaska']]);
cMap.polyDataSources([centigon.locationIntelligence.CMapAnalytics.DATA_PROVIDERS.SHAPE_DATAPROVIDER]);
cMap.layerTypes([centigon.mapping.Layer.TYPE.POLY]);
cMap.locations([["https://gmapsplugin.net/cmapsanalytics/assets/shapes/usstates.shp"]]);
cMap.panTo("USA");
cMap.zoomLevel(3);
Do you mean shapefile as in an Esri shapefile? Either way, you should be able to perform the conversion using ogr2ogr, which is available in the GDAL packages. You need the .shp file and ideally the corresponding .dbf file (which will provide contextual information).
Also, consider using a tool like MapShaper to reduce the complexity of your shapefiles before transforming them into KML; you'll reduce filesize substantially depending on how much detail you need.
Free "Export to KML" script for ArcGIS 9
Here is a list of available methods that someone found.
Also, it seems to me that the most efficient representation of a polygon layer is by using Google Maps API's polyline encoding, which significantly compresses lat-lng data. But getting into that format takes work: use ArcMap to export Shape as lat/lng coordinates, then convert into polylines using Google Maps API.
Just to update these answers, ESRI has included this tool, known as Layer to KML in ArcMap 10.X. Also, a Map to KML tool exists.
Simply import the desired layer (vector or raster) and choose the output location, resolution, etc. Very simple tool.
2018 already... I've found this fantastic online tool http://mapshaper.org/ to convert from ESRI shapefiles to SVG, TopoJSON, GeoJSON.
Here is the explanation of how to use it https://www.statsilk.com/maps/convert-esri-shapefile-map-geojson-format
Fast and straightforward! :)