WMS GetFeatureinfo for featurelayers - wms

I'm looking the way how to use browser to query all WMS features( with all attributes the feature have) by just defining the layer parameter or what parameters I need to add to get desired result? Request all features WMS is serving, output format must be txt, gml or xml.
Something like this...
wms?request=GetFeatureInfo&QUERY_LAYERS=my_layer&info_format=application/vnd.ogc.gml&select_all_features.

It's not possible, a WMS GetFeatureInfo operation fetches a point location (pixel coordinate) in a map image (created through a GetMap operation).
Also a WMS also doesn't serve out features it serves out images (or videos) that are representations of some input often, but not always, a vector data set.
What you need is for there to be a WFS (or WCS) these are 'download' services that let you get at the actual data.

It is not possible using WMS, but using WFS you can get all the GetFeatureInfo and also apply some limited amount of conditions to get the desired results.
For this you need to use WFS REQUEST=GetFeature
The documentation for WMS GetFeature describes the various options in more details.
A simple example would be
GET
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype&
count=N
GET
http://example.com/geoserver/wfs?
service=wfs&
version=1.1.0&
request=GetFeature&
typeName=namespace:featuretype&
maxFeatures=N
If you want to filter by BBOX you can use the following, as mentioned in the documentation
POST
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeNames=namespace:featuretype&
srsName=CRS&
bbox=a1,b1,a2,b2
For me it worked with GET too.
Note if bbox=a1,b1,a2,b2 does not work, try bbox=a1,b1,a2,b2,CRS
For me even with srsName=CRS&bbox=a1,b1,a2,b2 I got "features": [], with srsName=CRS&bbox=a1,b1,a2,b2,CRS I got results

Related

Chrome developer tools - Network - how to filter only POST and PATCH requests?

In the Chrome browser - Chrome developer tools - Network - I can show only POST requests by putting "method:POST" in the Filter search box.
What filter should I use in order to see both PATCH and POST requests?
The filter option is quite powerful, but it's limited to only using AND (conjunction). So simple workaround would be to use negatives...
For instance, in your case you could create a filter like this:
-method:GET -method:OPTIONS -method:PUT
This should filter out most of the requests. If you have other offending HTTP verbs you can easily add them.
Like me, I'm guessing many people came to this thread and don't necessarily need to filter to both POST and PATCH. That said, you can just use the filter like this to filter to POST requests:
On the Network Tab, in the filter box, type in:
method:POST
Unfortunately, you can't filter on multiple HTTP methods, or multiple pre-defined filters in general, such as using both method and domain.
You also can't mix a pre-defined filter and a normal text based one, as I discovered when answering How to filter by both text and property in Chrome DevTool's network panel?
You will have to filter one at a time, or alternatively if there's a lot of requests, you could export the HAR and filter based on the JSON output. I gave an example of parsing the JSON here if that helps.

Pagination in Arcgis wfs request

Is it possible to send WFS request with pagination? I tried with STARTINDEX but it's not working. I want to fetch features within a certain limit
Eg: http://example.com/ArcGIS/services/<mapping service name>/MapServer/WFSServer?VERSION=1.1.0&SERVICE=WFS&REQUEST=GetFeature&TYPENAME=<type name>&STARTINDEX=10&MAXFEATURE=10
Or: how will I fetch only objectid / featureid with WFS request so that I can send filter with request?
Well to answer your last question first to request an object by featureID use something like:
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeName=namespace:featuretype&
featureID=feature
To do the pagination you use something like:
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeName=namespace:featuretype&
startindex=0&
maxFeatures=10
Some notes on this however. I have only tested against Geoserver and I know that in version 2.1.x of geoserver the startindex has no affect on the results. I know it does work in version 2.3.x. If you are using a particular version of Geoserver I would suggest you look it up. I am not sure what is supported in other applications that serve out wfs. You will need to check with them but what I have given above is in accordance with the WFS spec.
One final thing is you may want to add some sorting when doing this. i.e.
http://example.com/geoserver/wfs?
service=wfs&
version=2.0.0&
request=GetFeature&
typeName=namespace:featuretype&
startindex=0&
maxFeatures=10&
sortBy=namespace:field
The reason for this is that without sorting when data is updated the data may change between requests meaning you may not see results ect between pages. That is still possible even with sorting, particularly if not sorting on ID or not using an incremental style ID field. However normally sorting on an ID field will ensure consitancy in paging.
As you are using ArcGis some of that may not be relevate to you. I am pretty sure however that the latest versions of Arc Gis support the WFS Spec for the startindex field.

rendering a json with direction service

when i make a request for a specific latlang direction service responses with the same json. so instead of making the same requests always, i want to store the json somehow.i tried parsing the json and sent to my function which i render the responses, but it didn't work. is something like this even possible?
var direction = JSON.parse('{"routes":[{"bounds":......}');
directionRenderer.setDirections(direction);
It's not possible by using directionRenderer.setDirections() , because not all properties of a directionsResult may be stored in JSON.
But you may of course draw the route on your own, fetch the important details (LatLng's, descriptions etc. out of the directionsResult and use them to 1. draw a polyline and 2. providing route-details)

Google Directions API, reduce XML output size

I'm using the Google Directions API specified here
https://developers.google.com/maps/documentation/directions/
it's working good, but the XML returned is a bit large, I don't need all the data they give.
the questions is, can I ask for a specific set of results?!
in my case, I want in "step" only "start_location" and "html_instructions".
You can't set a filter on resultset like you have mentioned above. If XML's size is too large , you can use JSON instead. Google recommends to use JSON format:
We recommend that you use json as the preferred output flag unless
your service requires xml for some reason. Processing XML trees
requires some care, so that you reference proper nodes and elements.
Reference: https://developers.google.com/maps/documentation/directions/#XML

How to get Google Maps Public Transit Directions by HTTP server-side request

I use such urls like:
http://maps.google.com/?saddr=546%206th%20Avenue,%20New%20York,%20NY%2010011%20(Sixth%20Avenue,%20New%20York)&daddr=W%20103rd%20St,%20New%20York,%20NY%20&dirflg=r
But it returns full html page. Does anybody know how to get such info in json or xml or any parsable format?
I need public transit.
You just add &output=json to the end of the url.
I'd like to extend Mathias's answer a little bit.
There's no official Google Transit API at the momemnt. Transits are provided by agencies, and most of Transits are not public. So, Google is not allowed to open them as API.
You may try to consume the "unofficial" data using your link + "&output=json".
However, the result won't be a valid JSON. Instead, that's something, that can be easily converted to a JavaScript object. (The differences are: there is no quotes around property names,
the strings are not properly encoded etc.)
Imagine you got this JavaScript object. However, it won't allow you to easily get the structured route details. Object's properties contain the route points coordinates, but no descriptions. The only place where the descriptions may be found is 'panel' property, which contains a chunk of HTML text (you may find a link to the sample of HTML in my blog post)
So, you'll have to convert this HTML into XML (X-HTML) and then build the parser of this XML to get the essence data of a trip.
Seems like a bit of overkill to me. Having in mind, that "unofficial" API may change in the future, including slight changes in 'panel' HTML structure that will kill your parser.
#MathiasLin, how did you overcome this?
Google Maps Javascript v3 and the Directions Web Service now has this capability as per :
https://googlegeodevelopers.blogspot.in/2012/06/public-transit-routing-and-layer-now.html
Update:
Latest server side API docs:
https://developers.google.com/maps/documentation/directions/get-directions
Re choosing public transport - it seems that it defaults to public transport now (at least when I use it).
Changing the last URL parameter, dirflg=r, into dirflg=w switches the directions to walking mode.
Plus see:
Walking, bicycle and public transport directions with time required in each mode , iPhone
for more detail about the parameters.
Google direction API response is in HTML, JSON format please check https://developers.google.com/maps/documentation/javascript/directions?hl=lv
& section 'The DirectionsResult Object'