All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cube.geojson.MultiPolygon Maven / Gradle / Ivy

Go to download

Simple dynamic GeoJson parsing utility for Java, with support for Elasticsearch

The newest version!
package com.cube.geojson;

import java.util.List;

public class MultiPolygon extends Geometry>>
{
	public MultiPolygon()
	{
	}

	@Override public void finishPopulate()
	{
		double top = 0, btm = 0, left = 0, right = 0;
		if (getCoordinates() != null && getCoordinates().size() > 0)
		{
			top = getCoordinates().get(0).get(0).get(0).getLatitude();
			btm = getCoordinates().get(0).get(0).get(0).getLatitude();
			left = getCoordinates().get(0).get(0).get(0).getLongitude();
			right = getCoordinates().get(0).get(0).get(0).getLongitude();
			for (List> lists : getCoordinates())
			{
				for (List list : lists)
				{
					for (LngLatAlt lngLatAlt : list)
					{
						if (top < lngLatAlt.getLatitude())
						{
							top = lngLatAlt.getLatitude();
						}
						if (btm > lngLatAlt.getLatitude())
						{
							btm = lngLatAlt.getLatitude();
						}
						if (left > lngLatAlt.getLongitude())
						{
							left = lngLatAlt.getLongitude();
						}
						if (right < lngLatAlt.getLongitude())
						{
							right = lngLatAlt.getLongitude();
						}
					}
				}
			}
		}
		double[] bbox = new double[]{left, btm, right, top};
		setBbox(bbox);
	}

	public MultiPolygon(Polygon polygon)
	{
		add(polygon);
	}

	public MultiPolygon add(Polygon polygon)
	{
		coordinates.add(polygon.getCoordinates());
		return this;
	}

	public boolean contains(Point point)
	{
		for (List> coordinate : coordinates)
		{
			if (GeoJson.pointInPolygon(coordinate, point))
			{
				return true;
			}
		}

		return false;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy