Kulturhistoriska_lamningar:kulturhistoriska_lamningar_point
To retrieve GeoJSON objects from the specified Web Feature Service (WFS) endpoint, you can construct a GetFeature request with the outputFormat parameter set to application/json. Here's how you can do it:
-
Identify the Layer Name: First, determine the exact name of the layer you wish to access. You can find this information in the WFS capabilities document available at:
https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?request=GetCapabilities&service=WFSOpen this URL in your browser and look for the
<Name>tags within the<FeatureTypeList>section to identify available layer names. -
Construct the GetFeature Request: Once you have the layer name, you can request its features in GeoJSON format by constructing a URL like the following:
https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=your_layer_name&outputFormat=application/jsonReplace
your_layer_namewith the actual name of the layer you're interested in. -
Execute the Request: Paste the constructed URL into your web browser or use a tool like
curlto execute the request. The server should respond with the features in GeoJSON format.
For example, if the layer name is Kulturhistoriska_lamningar:historical_sites, your request URL would be:
https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=Kulturhistoriska_lamningar:historical_sites&outputFormat=application/json
This approach leverages GeoServer's support for GeoJSON output via WFS, as detailed in the GeoServer documentation. citeturn0search0
Ensure that the layer name is correct and that the server supports the GeoJSON output format. If you encounter any issues, refer to the GeoServer WFS documentation or contact the service provider for assistance.
Great questions! You can filter WFS queries using the Filter Encoding (CQL, OGC Filters, or bounding box queries) to fetch only objects in a particular area or with specific attributes. Below are different approaches to achieve this:
You can use a bounding box (BBOX) filter to fetch features within a specific area.
https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?
service=WFS&
version=1.0.0&
request=GetFeature&
typeName=your_layer_name&
outputFormat=application/json&
bbox=minx,miny,maxx,maxy,EPSG:4326
Replace:
your_layer_namewith the actual name of the layerminx, miny, maxx, maxywith the coordinates of the bounding boxEPSG:4326with the correct projection if needed (WGS 84 in this case)
You can use CQL (Common Query Language) filters to query objects with specific attributes.
https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?
service=WFS&
version=1.0.0&
request=GetFeature&
typeName=your_layer_name&
outputFormat=application/json&
CQL_FILTER=status='active'
You can also filter numerical values, for example:
-
Fetch objects where
year > 1900CQL_FILTER=year>1900 -
Fetch objects where
category = 'church'CQL_FILTER=category='church'
You can combine a BBOX filter with an attribute filter using CQL.
https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?
service=WFS&
version=1.0.0&
request=GetFeature&
typeName=your_layer_name&
outputFormat=application/json&
CQL_FILTER=BBOX(geometry, minx, miny, maxx, maxy) AND status='active'
https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?
service=WFS&
version=1.0.0&
request=GetFeature&
typeName=your_layer_name&
outputFormat=application/json&
CQL_FILTER=BBOX(geometry, minx, miny, maxx, maxy) AND year>1900
If the server does not support CQL, you can use OGC XML filters. This is more complex but more flexible.
Let me know if you need an example of that! 🚀
Yes! You can retrieve unique values from an attribute using a WFS GetFeature request combined with filtering and post-processing. However, WFS itself does not have a direct "DISTINCT" or "GROUP BY" function like SQL. Instead, you need to retrieve all values and extract unique ones on the client side.
You can retrieve features and then extract unique values from a specific attribute (e.g., category) in your script or GIS tool.
https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?
service=WFS&
version=1.0.0&
request=GetFeature&
typeName=your_layer_name&
outputFormat=application/json&
propertyName=category
🔹 propertyName=category ensures that only the category field is returned, reducing data size.
Since WFS does not return distinct values, you can process the response in Python, JavaScript, or GIS tools.
import requests
import json
url = "https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=your_layer_name&outputFormat=application/json&propertyName=category"
response = requests.get(url)
data = response.json()
# Extract unique values
unique_categories = set(feature["properties"]["category"] for feature in data["features"])
print(unique_categories)If you already know some values and want to confirm their existence, you can use:
CQL_FILTER=category IN ('church', 'castle', 'bridge')
But this requires you to know possible values beforehand.
If you have access to GeoServer's backend (PostGIS database), you can create a SQL View:
SELECT DISTINCT category FROM your_table;Then expose this as a new WFS layer.
- WFS does not have a built-in "DISTINCT" function.
- Use
propertyName=your_attributeto limit the data. - Extract unique values on the client side using Python, JavaScript, or GIS software.
- If you control the server, use a SQL View with
DISTINCT.
Would you like an example for a different tool like JavaScript or QGIS? 🚀
That sounds great! If you're using JavaScript, you can easily fetch and extract unique values like this:
fetch("https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=your_layer_name&outputFormat=application/json&propertyName=category")
.then(response => response.json())
.then(data => {
const uniqueCategories = [...new Set(data.features.map(f => f.properties.category))];
console.log(uniqueCategories);
})
.catch(error => console.error("Error fetching data:", error));- Fetches the WFS data with only the
categoryattribute. - Extracts all
categoryvalues from features. - Uses
new Set()to get unique values. - Logs the result.
🚀 Now you can integrate this into a web app or a map! Let me know if you need further tweaks. 😃
fetch("https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=kulturhistoriska_lamningar_point&outputFormat=application/json&propertyName=lan") .then(response => response.json()) .then(data => { const uniqueCategories = [...new Set(data.features.map(f => f.properties.category))]; console.log(uniqueCategories); }) .catch(error => console.error("Error fetching data:", error));
fetch("https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=kulturhistoriska_lamningar_point&outputFormat=application/json") .then(response => response.json())
fetch("https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=Kulturhistoriska_lamningar:kulturhistoriska_lamningar_point&outputFormat=application/json") .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error("Error fetching data:", error));
fetch("https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=Kulturhistoriska_lamningar:kulturhistoriska_lamningar_point&outputFormat=application/json") .then(response => response.json()) .then(data => console.log(data)) .then(data => { const uniqueCategories = [...new Set(data.features.map(f => f.properties.category))]; console.log(uniqueCategories); }) .catch(error => console.error("Error fetching data:", error));
fetch("https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=Kulturhistoriska_lamningar:kulturhistoriska_lamningar_point&outputFormat=application/json") .then(response => response.text()) // Read as text first .then(data => { console.log("Raw response:", data); // Log full response return JSON.parse(data); // Try parsing JSON }) .then(data => console.log("Parsed JSON:", data)) .catch(error => console.error("Error fetching data:", error));
fetch("https://inspire-raa.metria.se/geoserver/Kulturhistoriska_lamningar/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=Kulturhistoriska_lamningar:kulturhistoriska_lamningar_point&outputFormat=application/json") .then(response => response.json()) .then(data => { console.log("Data received:", data); // Inspect the entire data object
// Log the first feature's properties for inspection
console.log("First feature properties:", data.features[0].properties);
// If 'category' doesn't exist, you can change it to another valid property like 'lamningtyp' or 'kommun'
const uniqueCategories = [...new Set(data.features.map(f => f.properties.lamningtyp))];
console.log("Unique lamning types:", uniqueCategories);
}) .catch(error => console.error("Error fetching data:", error));