Transform cardinal points in latitude and longitude in java

2

I have a Java program in which I use an object type that stores the puntos cardinales of a place (north, south, east and west) and I need to transform it into latitud and longitud .

How can I do it? Do I need an external library?

Thanks in advance

UPDATE

I receive this information, and from it I have to get a point:

"geometry": [{"north": 74.4, "south": 32.6, "west": 26.0, "east": 42.4}]}

With them I need to generate a POINT (long, lat)

UPDATE 2

I can also get this information in POLYGON format:

areaOfInterest": "POLYGON((7.67798 45.11909,7.60176 45.06504,7.66047 45.00936,7.70476 45.06285,7.736 45.10067,7.67798 45.11909))"

Is it possible from this POLYGON to obtain a POINT like the following?

  "location": "POINT(7.6567492 45.0651474)"
    
asked by jjmartinez 03.11.2017 в 09:57
source

1 answer

3

You have a BBOX or Bounding Box , which is formally represented by a list of the following way:

[xmin, ymin, xmax, ymax]

Removing the midpoint is trivial:

var bbox = {"north": 74.4, "south": 32.6, "west": 26.0, "east": 42.4};

var { north: ymax, south: ymin, west: xmin, east: xmax } = bbox;

var puntoMedio = [xmin + (xmax-xmin)/2, ymin + (ymax - ymin)/2];

var featurebbox = new ol.Feature({
    geometry: new ol.geom.Polygon([
      [
        [xmin, ymin], [xmax, ymin],
        [xmax, ymax], [xmin, ymax], [xmin, ymin]
      ]
    ])
});

var featurepm = new ol.Feature({
  geometry: new ol.geom.Point(puntoMedio)
});

var layer = new ol.layer.Vector({
  source: new ol.source.Vector()
});

layer.getSource().addFeature(featurebbox);
layer.getSource().addFeature(featurepm);

var map = new ol.Map({
  layers: [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    })
  ],
  target: 'map',
  controls: ol.control.defaults({
    attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
      collapsible: false
    })
  }),
  view: new ol.View({
    center: [0, 0],
    projection: 'EPSG:4326',
    zoom: 2
  })
});

map.addLayer(layer)
#map, html, body {
  width: 100%;
  height: 100%;
  margin:0;
  padding: 0;
}
<link rel="stylesheet" href="https://openlayers.org/en/v4.4.2/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v4.4.2/build/ol.js"></script>
<div id="map"></div>

PS: Since I see that you are using Java and that you are receiving representations of the geometry in WKT format, you may be interested in JTS to make the job easier and more bearable.

    
answered by 03.11.2017 / 12:02
source