geoserver cqlfilter
How to get the BBox for a polygon feature getting using cqlfilter
Wiki topics:
CRY · Crypto & Web3
geoserver cqlfilter
How to get the BBox for a polygon feature getting using cqlfilter
const wfsUrl = "http://XX.XX.XX.XX:8080/geoserver/wfs" +
"?service=WFS" +
"&version=1.1.0" +
"&request=GetFeature" +
"&typeName=workspace:layer_name" + // Replace with your layer name
"&CQL_FILTER=field_name='" + stateCode + "'" + // Replace with your CQL filter
"&outputFormat=application/json";
fetch(wfsUrl)
.then(response => response.json())
.then(data => {
if (data && data.features && data.features.length > 0) {
let [minX, minY, maxX, maxY] = [Infinity, Infinity, -Infinity, -Infinity];
data.features.forEach(feature => {
// Check if the geometry coordinates are present
const coordinates = feature.geometry?.coordinates;
if (coordinates) {
coordinates.flat(Infinity).forEach((value, index) => {
if (index % 2 === 0) { // X coordinate
minX = Math.min(minX, value);
maxX = Math.max(maxX, value);
} else { // Y coordinate
minY = Math.min(minY, value);
maxY = Math.max(maxY, value);
}
});
} else {
console.warn('Feature does not contain geometry:', feature);
}
});
// Ensure valid bounding box was calculated
if (minX !== Infinity && minY !== Infinity && maxX !== -Infinity && maxY !== -Infinity) {
const boundingBox = [[minY, minX], [maxY, maxX]];
console.log("Calculated Bounding Box:", boundingBox);
map.fitBounds(boundingBox); // Zoom to the bounding box on the map
} else {
console.warn("Unable to calculate a bounding box from the geometry.");
}
} else {
console.warn("No features found with the specified filter.");
}
})
.catch(error => {
console.error("Error fetching WFS GetFeature:", error);
});

Result
메타데이터
- post_id
- 984e5ef928ba
- slug
- geoserver-cqlfilter-984e5ef928ba
- url
- https://medium.com/@tanishcb/geoserver-cqlfilter-984e5ef928ba
- canonical_url
- https://medium.com/@tanishcb/geoserver-cqlfilter-984e5ef928ba
- author_url
- https://medium.com/@tanishcb
- status
- ok
- fetched_at
- 2026-07-22 07:06:13