Hot answers tagged

18

According to Mike Bostock (and other contributors to the TopoJSON extension): TopoJSON is an extension of GeoJSON that encodes topology. Rather than representing geometries discretely, geometries in TopoJSON files are stitched together from shared line segments called arcs. TopoJSON eliminates redundancy, offering much more compact representations of ...


14

The L.GeoJson class has a built in filter option that you can use to filter your data. Just pass it a function that will return true for the features you want to show: var picnic_parks = L.geoJson(myJson, {filter: picnicFilter}).addTo(map); function picnicFilter(feature) { if (feature.properties.Picnic === "Yes") return true } Here is a fiddle with a ...


14

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.


13

You cannot apply this particular example without understanding the JSON format: your external file "file.json" is not an .json file A correct format would be (without var states = [:) { "type": "Feature", "properties": {"party": "Republican"}, "geometry": { "type": "Polygon", "coordinates": [ [ [ -84.32281494140625, 34....


12

Look at the samples on the specification site. You'll need to write a script in the language of your choice that will get you from [ {"date":"2014-09-25","time":"20:49:09","lat":"53.269","lon":"6.935","depth":"3.0","place":"Meedhuizen","mag":"1.5","type":"GH","last":"True"}, {"date":"2014-09-24","time":"23:49:36","lat":"53.351","lon":"6.693","depth":"3.0","...


11

So this python script will take a json input file as detailed above and write properly formatted geojson to the output file. run the script in terminal by doing python scriptname.py input_file.json output_file.json #! usr/bin/env python from sys import argv from os.path import exists import simplejson as json script, in_file, out_file = argv data = ...


11

Geotools as a support for geojson. See here. Otherwise, you could simply use a typical JSON parser (such as json-simple) together with the geoJSON spec, which is really easy to use. The best solution depends on what you want to do with the parsed information.


10

The problem is that your string inputFeature_json has special characters that are not in the ascii encoding. If you have characters that are not in the english alphabet they can cause encoding errors. Try to convert the string as unicode. for example: # Script arguments inputFeatures_json = arcpy.GetParameterAsText(0) #wtite to file jsonFileName = '...


10

You could write a simple script in (for example) Python that will process the data for you. import json from itertools import chain Open the file and read the data into a Python dictionary: isil = json.load(open('isil.en.json')) The points object is just a list of feature collections, so you can use the python itertools library to help chain the features ...


10

With Shapely: https://shapely.readthedocs.io/en/latest/manual.html#polygons The polygon in code below must be Polygon object. import random from shapely.geometry import Point def generate_random(number, polygon): list_of_points = [] minx, miny, maxx, maxy = polygon.bounds counter = 0 while counter < number: pnt = Point(random....


8

You can't get a JSON result from the XAPI-compatibility endpoint. Instead, use the standard Overpass API (“interpreter”) endpoint and put the [out:json]; at the very start of your ql query: https://www.overpass-api.de/api/interpreter?data=[out:json];node[highway=speed_camera](43.46669501043081,-5.708215989569187,43.588927989569186,-5.605835010430813);out%...


7

You can also see Esri's geojson-utils on Github that "contains [javascript] utilities for converting GeoJSON to other geographic json formats and vice versa. Currently only GeoJSON to Esri JSON has been developed. Also, note that only geometries in the WGS84 coordinate system are supported."


7

It's fairly easy with urllib2. Say you've got a gigantic url like this: http://myserver/path/to/a/thing?json1={"data":[1,2,3,4,5]}&json2={"data":[1,2,3,4,5]}&json3={"data":[1,2,3,4,5]} All you need to do is take the query (everything after the ?) and jam it in the data argument to urlopen. import urllib2 import urlparse # GET return_data = ...


7

Solved by himself : Adding ?compression=false to the request query will output unencoded data. A proof that smeagol and gollum can work together. ( what is compression, my precious? )


7

I got it to work using Geoserver 2.3 and Leaflet with WFS 1.0.0 here. When I changed to version 1.1.0 and 2.0.0 it returned the same json object as 1.0.0 but neither rendered on the map. Not sure why and it's a bit beyond me. Here's what I'm using: var rootUrl = 'http://tomcat.capecodgis.com/geoserver/capecodgis/ows'; var defaultParameters = { ...


7

Your generated GeoJSON is valid JSON, no problem. But, it's not valid GeoJson, as you can see here: http://geojsonlint.com/ The problem seems to be that the features-array in your featurecollection contains three features, two with geometry:none and one with just geometry (which is also string-encoded). So, in short: Your OpenLayers-code seems fine, the ...


7

From the Leaflet Polygon examples, here is one way with a Switch Statement: var states = [{ "type": "Feature", "properties": {"party": "Republican"}, "geometry": { "type": "Polygon", "coordinates": [[ [-104.05, 48.99], [-97.22, 48.98], [-96.58, 45.94], [-104.03, 45.94], [-104.05, 48.99] ]] } }, { "type": ...


7

You'll have to patch existing software in order to use such a format, but there's nothing wrong with embedding GeoJSON in other JSON formats. JSON is super extensible like this. Every object is its own namespace. If you look in the other direction, there are some applications, namely Leaflet, http://geojson.io, Fiona's command line programs, that will ...


7

To parse or deserialize geojson in Java REST webservice, i prefere to use geojson-jackson , which integrate itself very nicely with jackson.


7

Because it's a "oneshot", you can do it manually (also possible running via Node) Open a JavaScript console in your browser. You need to loop to get an array of array of Feature (because each FeatureCollection have one or more Feature) Then, you will use the flatten function to transform the array of array into an array (a recursive function borrowed from ...


7

You can use Turf.js to calculate the centroids of the polygons. Just include it in your HTML head. In my case, I am using the CDN: <script src="https://unpkg.com/@turf/turf@3.5.2/turf.min.js"></script> In the following code I am using onEachFeature to check whether the current feature is a polygon, since it would not make sense to convert ...


6

i dont know where you want to merge but you can do it with python as following code. merged = { firstObj : {"parent_area": null, "generation_high": 1, "all_names": {"default": ["OSM Default", "South Georgia"]}, "id": 14455, "codes": {"osm_rel": "1983629"}, "name": "South Georgia", "country": "G", "type_name": "OSM Administrative Boundary Level 3", "...


6

For those wondering, at version 2.13.0, GeoServer started supporting HStore and JSON columns for PostGIS data stores. The site says: The PostGIS data store now has simple support for HStore and JSON columns. HStore is returned as a Map and will render as a JSON formatted string field in common WFS output formats, while JSON is read as a string and ...


6

Look at the docs! You'll see that you need to define other callback methods on the L.geoJson object. Namely: L.geoJson(data, { style: function (feature) { return {[style properties here}; }, onEachFeature: function (feature, layer) { layer.bindPopup(feature.properties.Sheet_Num + </br> + feature.properties.Date); } }).addTo(...


6

Yes, you can import non-geo JSON files into QGIS but there are no native method for this in QGIS. It's because in your link, it's non tabular data. For each "column" (like income) per country, you have year and value. You need to preprocess the data to change the structure to flatten it to 2 dimensions. One choice could be to use PyQGIS console to solve ...


6

Geojson is technically already in JSON format. What do you need to do with the data? You can save geojson data to a file with a .json extension. You can also encode the geojson data to get a string just like any other JSON data.


6

The problem appears to be here: geometry = [Point(xy) for xy in zip(cities_df['latitude'], cities_df['longitude'])] Latitude is y, longitude is x. Just swap the keys. You can see the transposition in the image below.


5

ArcGIS now supports GeoJSON Now ArcGIS Online has GeoJSON through ArcGIS Rest API URL. All you need to do is set f=geojson in the URL and configure the service. Be aware, by default, ArcGIS online will not allow GeoJSON export until you explicit permit other output formats. Here is how to enable the export: Log into arcgis online click the feature layers, ...


5

You must use a geoJSON file (The GeoJSON Format Specification) and not a simple JSON file. Your example is not a GeoJSON file (no 'geometry' tag for example) As example, GitHub announced that you can now automatically view any GeoJSON files that may be in a repository inside an interactive map driven by MapBox technology (see my example AAC.geojson) And ...


5

Because Features to JSON outputs ArcGIS JSON geometries, you'd have to use something like Terraformer to convert to GeoJSON if you intended on working with the data as a client-side graphics layer in Leaflet. edit: 30/9/15 Esri's open source Leaflet plugins make it easy to fetch data dynamically from ArcGIS Server and ArcGIS Online and display in Leaflet.


Only top voted, non community-wiki answers of a minimum length are eligible