mapbox gl geojson style - geojson

I try to reproduce the capture below within Mapbox GL. The colors are added for the sake of readability, yet to be able to customize colors is not mandatory. The key aspect is the different lines weights.
I've read about styling in Mapbox GL here and there. To add as many style layers that there are different weights is not an option. I tried it with two thousands LineStrings and the performances are not acceptable.
I've crawled several github issues there about data driven styles in mapbox GL, but I cannot figure out if what I need is on the road map.
Below a MWE of the GEOJSON I've used to produce the image above.
{
"type": "FeatureCollection",
"features": [
{
"geometry": {
"type": "LineString",
"coordinates": [[2.3420237, 48.9437736],
[2.3430249, 48.9462233],
[2.3428777, 48.9469687]]
},
"type": "Feature",
"properties": {
"color": "#0000FF",
"weight": 5
}
},
{
"geometry": {
"type": "LineString",
"coordinates": [[2.3880359, 48.9077387],
[2.3885364, 48.9072262],
[2.3886376, 48.9071376],
[2.3891088, 48.9066521]]
},
"type": "Feature",
"properties": {
"color": "#FF0000",
"weight": 15
}
}
]
}

There's documentation here on adding a styling a lineString from GeoJSON. Here's an additional example that demonstrates two lineStrings on a map with two different weights/colors: http://bl.ocks.org/tristen/5f807d44726b401b727f3ab06c7ed864
I tried it with two thousands LineStrings and the performances are not acceptable.
A more performant data format for thousands of points is to convert your GeoJSON to vector tiles. There's an example of adding a vector tile layer to a map using Mapbox GL JS here: https://www.mapbox.com/mapbox-gl-js/example/vector-source/

Related

What is the correct way to add a bbox in a GeoJSON object?

I'm generating some GeoJSON documents and I was unsure how to properly add a bbox to a geometry.
Do I need to necessarily create a Feature object to add the bbox (example 1) or can I do this in the geometry itself (example 2)?
The GeoSON specification (https://www.rfc-editor.org/rfc/rfc7946#appendix-A) presents examples only with the bbox in a GeoJSON object of type Feature, however, validators accept the two modes of inserting the bbox.
Example 1:
In this example, the bbox is an element of the GeoJSON object of type Feature.
{
"type": "Feature",
"properties": {"id": 1, "Linha": null},
"bbox": [-48.573569106948469, -27.837770518544438, -48.417446881093412, -27.381161181879751],
"geometry": {
"type": "LineString",
"coordinates": [
[-48.417446881093412, -27.381161181879751],
[-48.573569106948469, -27.837770518544438]
]
}
}
Example 2:
In this other example, the bbox was included directly in the GeoJSON object with the geometry (LineString).
{
"type": "LineString",
"bbox": [-48.573569106948469, -27.837770518544438, -48.417446881093412, -27.381161181879751],
"coordinates": [
[-48.417446881093412, -27.381161181879751],
[-48.573569106948469, -27.837770518544438]
]
}
This is a good question, and you are right that the spec has incomplete examples. From the standard, look at the definition of a GeoJSON Object:
GeoJSON Object
A GeoJSON object represents a Geometry, Feature, or collection of Features.
A GeoJSON object is a JSON object.
A GeoJSON object has a member with the name "type". The value of the member MUST be one of the GeoJSON types.
A GeoJSON object MAY have a "bbox" member, the value of which MUST be a bounding box array (see Section 5).
Then, from the section on bounding boxes:
A GeoJSON object MAY have a member named "bbox" to include information on the coordinate range for its Geometries, Features, or FeatureCollections.
This is why the validators accept both of your examples. They are both valid geojson objects to have a bounding box on.
To help validate this in my own projects, I developed a set of matchers called jest-geojson that extends the Jest testing framework to make it easier to evaluate GeoJSON. Bounding box evaluation is included.

Change map projection in Cesium.js to match results from turf.js inside query

I am displaying a point and a polygon in Cesium.js, and using turf.js to check is the point inside the polygon.
When displayed in Cesium (or geojson.io), the point is clearly outside the polygon, as can be seen here:
http://geojson.io/#id=gist:kujosHeist/1030e392bd751daf5d9af57aa412a49c&map=3/46.80/-22.76
However, when I queried this on the turf.js issiues page:
https://github.com/Turfjs/turf-inside/issues/15
I was told it was because geojson, (and therefore Cesium) is "misrepresenting the point since it uses World Web Mercator projection (EPSG:3857)" and that "viewing the same point/polygon using WGS84 with QGIS" ...shows the point is inside the polygon.
So my question is: How can I change the map projection used in Cesium (and also in geojson.io if possible), so that the point is correctly displayed inside the polygon?
I am not sure how well geojson.io or Cesium will handle different coordinate systems, but you can specify a CRS element in your GeoJSON that indicates the coordinate system used by points of your features. This is added as a member under your feature collection. For example:
{
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
},
...the rest of your structure...
}
But like I said, it's up to the map display software to pay attention to your specified CRS and use it to project coords. If it doesn't support the coordinate system you have, then you'll need to pick some other map display software or convert the coords to a supported coordinate system.

What does this "classifiers": [] mean?

Hi I am currently trying to utilize Watson's Visual Reco Service and I am getting a really weird response. After reading the documentaion I am guessing this photo doesn't meet the threshold value but I am not actually sure. Here's the a snippet of one of my response:
{ "classifiers": [{
"classes": [ { "class": "classname", "score": 0.522029 } ],
"classifier_id": "normalLeft_329785087", "name": "normalLeft" } ],
"image": "Testing_Left.zip/80589N.jpg"
},
{
"classifiers": [],
"image": "Testing_Left.zip/81860Y.jpg"
},
Another issue related to this is that sometimes my zip files aren't recognized by watson. Is there any particular reason why watson would have difficulties with zip files?
Thanks for the help in advance.
After reading the documentaion I am guessing this photo doesn't meet the threshold value but I am not actually sure.
That's exactly it. It means none of the classes in the classifiers applied to the image Testing_Left.zip/81860Y.jpg returned a score above the threshold. By default for custom classifiers, the threshold is 0.5 You can set the threshold parameter to 0 if you would like to see all each score per class per image.
Is there any particular reason why watson would have difficulties with zip files?
We have observed problems with some zip files with files or directories inside which have extended character sets, such as accented letters. Could that be the case for you?

Openlayers 3 - Load Geometric data into Vector Layer

UPDATE: The basic question is, if my GeoJSON delivered by the REST interface (Json data is visible at end of question) is a valid GeoJSON for the vector layer, because as soon as i add this as source for the vector layer, the layer is broken.
Currently there is no REST Interface to upload shapes, so i just took some valid coordinates from current shapes and created a static JSON on serverside
I try to make it possible that users can draw shapes (Polygons, Lines) on a vector layer and the i store the geometric data on a server and the next time the map is loaded it should be displayed again. But it seems somehow when i define my REST interface as source for the vector layer, that there is some problem as painting and adding objects into the vector layer does not work anymore.
Here the code i put together from OpenLayers Examples. First an image how it should look like:
I extracted the coordinates on the map with drawend event and built a REST interface where i could load the geometric data, this is the response i get for the vector layer source:
{
"type":"FeatureCollection",
"crs":{
"type":"name",
"properties":{
"name":"EPSG:2000"
}
},
"features":[
{
"type":"Feature",
"id":"1",
"properties":{
"name":"TEST1"
},
"geometry":{
"type":"LineString",
"coordinates":[
[
-5920506.46285661,
1533632.5355137766
],
[
-1882185.384494179,
234814.55089206155
]
]
}
}
]
}
But if i load this, nothing will be displayed and its not possible to draw on the layer anymore (if i remove the "source" attribute from the vector layer source it works again)
Here the complete code on pastebin: Example Code
I fixed the problem meanwhile, i was trying to load GeoJSON into my vector layer but the vector layer was always broken afterwards. As i was pretty new to open layers, i didn't notice my mistake, but i had syntax errors in my GeoJSON and the coordinates i supplied were also wrong.
After correcting the syntax and the coordinates everything is working as intended and as mentioned above EPSG:3857 was also the right thing to use. Sorry for my first messy experiences with open layers, but thanks for the friendly help ;)

Free City/State/Zipcode to Latitude/Longitude Database? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Is there a standard database of records mapping city/state/zip to lat/lng? I found this database, and the USPS has a simple (no lat/lng) API, but is there another recommended alternative?
Update: Found this too: http://www.geopostcodes.com/
Just a small note. Most of these 3rd party city/state/zip to lat/lng databases are based on the US Census Tiger data. Start with the Census 2000, the zip code data was replaced with ZCTA - which is an approximation of zipcodes. Here's an explanation from the Census site (from 2011):
ZIP Code Tabulation Areas (ZCTAs™) are a new statistical entity developed by the U.S. Census Bureau for tabulating summary statistics from Census 2000. This new entity was developed to overcome the difficulties in precisely defining the land area covered by each ZIP Code®. Defining the extent of an area is necessary in order to accurately tabulate census data for that area.
ZCTAs are generalized area representations of U.S. Postal Service (USPS) ZIP Code service areas. Simply put, each one is built by aggregating the Census 2000 blocks, whose addresses use a given ZIP Code, into a ZCTA which gets that ZIP Code assigned as its ZCTA code. They represent the majority USPS five-digit ZIP Code found in a given area. For those areas where it is difficult to determine the prevailing five-digit ZIP Code, the higher-level three-digit ZIP Code is used for the ZCTA code. For more information, please refer to the ZCTA (FAQ) Frequently Asked Questions Web page.
The link below is an updated explanation (2013):
http://www.census.gov/geo/reference/zctas.html
The OpenGeoCode.Org team
ADDED 12/17/13: Our (FREE) state/city/zip dataset (CSV) can be found at the link below. It is derived from public domain "government" datasets:
http://www.opengeocode.org/download.php#cityzip
Google offers this as a lookup. Can you do ajax calls from your app?
It's called webservices.
http://code.google.com/apis/maps/documentation/webservices/index.html
You'd want to use the Google Geocoding api.
It's simple to use, make a call to this url:
http://maps.googleapis.com/maps/api/geocode/json?address=sydney&sensor=false
Change "address=" to whatever you need (ie the city state and zip code)
It can also reply in xml. just change json to xml
http://code.google.com/apis/maps/documentation/geocoding/
Example Result
{
"status": "OK",
"results": [ {
"types": [ "locality", "political" ],
"formatted_address": "Sydney New South Wales, Australia",
"address_components": [ {
"long_name": "Sydney",
"short_name": "Sydney",
"types": [ "locality", "political" ]
}, {
"long_name": "New South Wales",
"short_name": "New South Wales",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "Australia",
"short_name": "AU",
"types": [ "country", "political" ]
} ],
"geometry": {
"location": {
"lat": -33.8689009,
"lng": 151.2070914
},
"location_type": "APPROXIMATE",
"viewport": {
"southwest": {
"lat": -34.1648540,
"lng": 150.6948538
},
"northeast": {
"lat": -33.5719182,
"lng": 151.7193290
}
},
"bounds": {
"southwest": {
"lat": -34.1692489,
"lng": 150.5022290
},
"northeast": {
"lat": -33.4245980,
"lng": 151.3426361
}
}
}
} ]
}
Then all you need to do is open up results[0].geometry.location.lat, and results[0].geometry.location.lng
[EDIT 8/3/2015]
The free non-commercial ZIP Code database I mentioned below has moved to softwaretools.com. Note: greatdata.com still has the premium ZIP Code data for enterprises.
Just a small note. Most of these 3rd party city/state/zip to lat/lng databases are based on the US Census Tiger data. [Andrew]
I'm a developer for a commercial ZIP Code Database company (GreatData). For low-end data, Andrew's recommendation is correct and if you know your way around census data, it's pretty easy to get it. Just know it may initially take some hours to get it right. If you prefer not to do the work yourself, you can get our free/non-commercial version here (it's pretty much what Andrew is suggesting with minor enhancements. It's updated every couple months).
For a really good explanation on what is missing in it (and more importantly, what's missing in most all low-end ZIP Code data that is based on census ZCTA data) versus a commercial grade, see here.
ps - regarding suggestions to use Google's API, I see this suggested a lot but unless you're displaying it in a google map, this violates Googles TOS. Specifically: "The Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited." You'll find StackOverFlow has several threads on those who's sites have been blocked.
Hope this is beneficial
This is an old thread, but I was looking for the same information recently and also came across this free database:
http://federalgovernmentzipcodes.us
Check out zcta. You can draw the geographic boundaries of a zip code using their data.
If you have a small number of US cities you can easily build up your own database from Google which gives you the co-ordinates straight on the search page without the need to follow any links, e.g. type:
chicago illinois longitude latitude

Resources