001/**
002 * Copyright (c) 2011, The University of Southampton and the individual contributors.
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification,
006 * are permitted provided that the following conditions are met:
007 *
008 *   *  Redistributions of source code must retain the above copyright notice,
009 *      this list of conditions and the following disclaimer.
010 *
011 *   *  Redistributions in binary form must reproduce the above copyright notice,
012 *      this list of conditions and the following disclaimer in the documentation
013 *      and/or other materials provided with the distribution.
014 *
015 *   *  Neither the name of the University of Southampton nor the names of its
016 *      contributors may be used to endorse or promote products derived from this
017 *      software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030package org.openimaj.vis.world;
031
032import java.util.List;
033
034import org.openimaj.math.geometry.shape.Shape;
035
036/**
037 *      Represents a single place in the world and it's bounds and shape.
038 *      Also includes various metadata about the country.
039 *
040 *      @author Sina Samangooei (ss@ecs.soton.ac.uk)
041 *      @author David Dupplaw (dpd@ecs.soton.ac.uk)
042 */
043public class WorldPlace
044{
045        /** The country's international code (ISOA2) */
046        private final String countryCode;
047
048        /** Full name of the country */
049        private final String name;
050
051        /** The shape of the country */
052        private final List<Shape> geoms;
053
054        /** The latitude position */
055        private final float latitude;
056
057        /** The longitude position */
058        private final float longitude;
059
060        /**
061         *      Construct a new world place.
062         *
063         *      @param name The country's name
064         *      @param countryCode The country's international code (ISOA2)
065         *      @param lat The latitude
066         *      @param lon The longitude
067         *      @param shape The shape of the country
068         */
069        public WorldPlace( final String name, final String countryCode,
070                        final float lat, final float lon, final List<Shape> shape )
071        {
072                this.name = name;
073                this.countryCode = countryCode;
074                this.latitude = lat;
075                this.longitude = lon;
076                this.geoms = shape;
077        }
078
079        /**
080         *      {@inheritDoc}
081         *      @see java.lang.Object#toString()
082         */
083        @Override
084        public String toString()
085        {
086                return String.format( "{%s: (%2.2f,%2.2f), Area: %s}", this.name,
087                                this.latitude, this.longitude, this.calculateArea() );
088        }
089
090        /**
091         *      Calculates the area of the country
092         *      @return The area of the country
093         */
094        public double calculateArea()
095        {
096                double total = 0;
097                for( final Shape geom : this.geoms )
098                        total += geom.calculateArea();
099                return total;
100        }
101
102        /**
103         * @return the shapes of this place
104         */
105        public List<Shape> getShapes()
106        {
107                return this.geoms;
108        }
109
110        /**
111         * @return the ISOA2 country code
112         */
113        public String getISOA2()
114        {
115                return this.countryCode;
116        }
117
118
119        /**
120         *      @return the countryCode
121         */
122        public String getCountryCode()
123        {
124                return this.countryCode;
125        }
126
127        /**
128         *      @return the name
129         */
130        public String getName()
131        {
132                return this.name;
133        }
134
135        /**
136         *      @return the latitude
137         */
138        public float getLatitude()
139        {
140                return this.latitude;
141        }
142
143        /**
144         *      @return the longitude
145         */
146        public float getLongitude()
147        {
148                return this.longitude;
149        }
150}