1

I am working on OpenLayers6. And I want to show the plots. But My plot data is not being rightly placed on original plot polygon.

What my concern is that I want to get the full-length coordinates, but getting only half coordinates data

Here is my Code from where i'm fetching the features of polygon.

var wmsSource = new TileWMS({
        url: "http://13.233.167.180:9090/geoserver/pinyard/wms",
        tileSize: 512,
        params: { LAYERS: "pinyard:home_plotmap", TILED: true },
        serverType: "geoserver",
        transition: 0.8,
      });

whenever the user clicks, I want to show the polygon features.
Here is the code of this.

map.on("singleclick", async function (evt) {
        // var element = popup.getElement();
        const coordinate = evt.coordinate;
        var viewResolution = map.getView().getResolution();
        var url = wmsSource.getFeatureInfoUrl(
          evt.coordinate,
          viewResolution,
          "EPSG:4326",
          {
            INFO_FORMAT: "application/json",
          }
        );
    if (url) {
      await fetch(url)
        .then((response) => response.json())
        .then((data) => {
          console.log(data);
          // I am getting data in console.
          // I am getting only short coordinates.

          if (data.features.length === 0) {
            overlay.setPosition(undefined);
          } else {

            const styles_green = [
              new Style({
                fill: new Fill({
                  color: "rgba(0, 255, 0, 0.3)",
                }),
                stroke: new Stroke({
                  color: "#ffcc33",
                  width: 2,
                }),
              }),
              new Style({
                geometry: function (feature) {
                  // return the coordinates of the first ring of the polygon
                  const coordinates = feature
                    .getGeometry()
                    .getCoordinates()[0];
                  return new MultiPoint(coordinates);
                },
              }),
            ];

            const geojsonObject = {
              type: "FeatureCollection",
              crs: {
                type: "name",
                properties: {
                  name: "EPSG:4326",
                },
              },
              features: [
                {
                  type: "Feature",
                  geometry: {
                    type: "Polygon",
                    coordinates: [data.features[0].geometry.coordinates[0]],
                  },
                },
              ],
            };

My concern is I want to get the data in full coordinates like this:

[[72.59962347256743, 23.00193887325614],
[72.60040131318172, 23.00193887325614],
[72.60054078805076, 23.00196850066428],
[72.60099676358334, 23.00196850066428]]

But, I'm getting Coordinates like this:

[[72.5996, 23.0019],
[72.6004, 23.0019],
[72.6005, 23.0019],
[72.6009, 23.0019]]
Mihir
  • 13
  • 3

1 Answers1

1

GeoServer allows you to how many decimal digits to use when outputting text coordinates on the global settings page. Be aware of using spurious amounts of precision when you don't have that much accuracy in your data. See this answer for more detail.

Ian Turton
  • 81,417
  • 6
  • 84
  • 185