<file_sep>import org.apache.log4j.Logger;

/**
 * Created by dvalo on 23.10.2016.
 * Data class for coordinate with 2 values longtitude and latitude
 */
public class Coordinate {

    static Logger log = Logger.getLogger(Coordinate.class.getName());

    private double x = 0;
    private double y = 0;

    //cordinatesPlaintText = [-122.48369693756104, 37.83381888486939]
    public Coordinate(String cordinatesPlaintText) {

        cordinatesPlaintText = cordinatesPlaintText.replaceAll("\\[","").replaceAll("]","");
        String[] coordinates = cordinatesPlaintText.split(",");
        if(coordinates.length==2) {
            this.x = Double.parseDouble(coordinates[0]);
            this.y = Double.parseDouble(coordinates[1]);
        }else{
            log.info("Coordinates does not have 2 values: "+cordinatesPlaintText);
        }
    }

    /**
     *
     * @return coordinates in format: [-122.48369693756104, 37.83381888486939], where [x,y]
     */
    public String getCoordinate(){
        String coordinate = "";
        coordinate ="["+x+","+y+"]";
        return coordinate;
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }
}
<file_sep># General course assignment

Build a map-based application, which lets the user see geo-based data on a map and filter/search through it in a meaningfull way. Specify the details and build it in your language of choice. The application should have 3 components:

1. Custom-styled background map, ideally built with [mapbox](http://mapbox.com). Hard-core mode: you can also serve the map tiles yourself using [mapnik](http://mapnik.org/) or similar tool.
2. Local server with [PostGIS](http://postgis.net/) and an API layer that exposes data in a [geojson format](http://geojson.org/).
3. The user-facing application (web, android, ios, your choice..) which calls the API and lets the user see and navigate in the map and shows the geodata. You can (and should) use existing components, such as the Mapbox SDK, or [Leaflet](http://leafletjs.com/).


# Application description
- Zobrazovanie parkov a pláží na území Slovenska podľa mesta v ktorom sa nachádzajú
- Zobrazovanie parkov a pláží na území Slovenska podľa mesta v ktorom sa nachádzajú alebo výber mesta kurzorom alebo aktuálnou GPS polohou
- Zobrazovanie parkov a pláží na území Slovenska podľa mesta v ktorom sa nachádzajú, podľa ich rozlohy
- Zobrazovanie parkov a pláží na území Slovenska ak sa okolo nich nachádzajú bary do špecifikovanej vzdialenosti - zobrazenie aj barov
- Zobrazovanie parkov a pláží na území Slovenska podľa toho, či sa v nich nachádza občerstvenie alebo wc

# Môj projekt (Hybridná aplikácia Web+Android+IOS)
- Map-based hybridná aplikácia
založená na Apache-Cordova, ktorá komunikuje s backendom, realizovaným v Jave pomocou frameworku Spark,využívaného na REST-ové volania. Front-end je vytvorený pomocou frameworku apache-cordova, ktorý nám umožnuje vybuildovať aplikáciu pre rôzne platformy(screenshots/platforma-android.png,screenshots/platforma-ios.png,screenshots/platforma-web.png,). Hybridnú aplikáciu sme zvolili, kvôli multiplaformovosti a jednoduchému prístupu k natívnym komponentom ako je GPS, ktorú využívame. Môžeme vyhľadať všetky pláže a parky v meste v ktorom sa práve nachádzame. Toto získame práve pomocou GPS.
  Front-end aplikáciu som vyexportoval ako webovú aplikáciu, spustiteľnú v ľubovoľnom prehliadači(Ja som používal Chrome) a zdrojáky priložil k odovzdaniu, pretože celý projekt zahrňujúci všetky platformy mal okolo 120MB. Projekt som uložil na googledrive, odkiaľ je možné si ho stiahnuť ().
  Zdrojové kódy webovej aplikácie, spustiteľnej v prehliadači som vložil do tohto repozitára do zložky front-end.
  Projekt sa spúšťa:
-na back-ende pomocou triedy /src/java/Main.java
-na front-ende pomocou súboru /front_end/index.html a logika k nemu je v súbore /scripts/index.js


- Databáza
Dáta sme získali z voľne dostupných datasetov, importovali ich vo formáte shapeFile pomocou postGis importera.
  S dátami administratívnych území bol problém, pretože geom hodota nebola správna a bolo potrebné celý shapeFile
  skonvertovať pomocou konvertera: (https://zbgis.skgeodesy.sk/zbgisconvert/). Využívali sme nasledujúce tabuľky:
- gis_osm_pois_free_1        -wc,bary
- gis_osm_pois_a_free_1      -obcerstvenie
- Parky                      -parky
- gis_osm_natural_a_free_1   -pláže
- hranice_obce_6             -mesta

- Back-end Pomocou fraeworku Spark pracujeme s REStovými volaniami.

Selecty som chcel pôvodne robiť pomocou MyBatis frameworku (http://www.mybatis.org/mybatis-3/) s využitím mapovača ale potom som sa rozhodol urobiť generátor selectov a kvôli tomu som ho nemohol použiť pretože musím selecty postupne vyskladávať podľa používateľových vstupov.

1. Zachytíme request.
2. Po zachytení requestu zoberieme argumenty a vytvoríme požadovaný select.
3. Bolo viacero zadefinovaných scenárov ako využívať rozlohu parkov, vzdialenosť barov a toho čo sa nachádza v parkoch, ale tie obmedzovali používateľa, preto som nevytvoril len natvrdo zadefinované selecty ale som vytvoril generátor na selecty, ktorý kombinuje rôzne možnosti, ktoré si používateľ môže zvoliť a tak využil všetky prvy rôznych scenárov naplno.
4. Ukážka vygenerovaného jednoduchého a zložitejšieho selectu:

              SELECT obce.nm2 AS cityName,ST_AsGeoJSON(obce.geom) AS city, ST_AsGeoJSON(park.geom) AS parky,park.name AS parkName
              FROM  Parky AS park,hranice_obce_6 AS obce
              WHERE  obce.nm2 LIKE '%'
              AND ST_WITHIN(park.geom, obce.geom)

              SELECT wc.name AS wcName,ST_AsGeoJSON(wc.geom) AS wcka,obce.nm2 AS cityName,ST_AsGeoJSON(obce.geom) AS city,ST_Area(park.geom::geography) AS rozloha, ST_AsGeoJSON(park.geom) AS parky,park.name AS parkName,obcer.name AS obcerName ,obcer.fclass AS obcerClass,ST_AsGeoJSON(obcer.geom) AS obcerstvenie,Obar.name AS obarName ,Obar.fclass AS obarClass,ST_AsGeoJSON(Obar.geom) AS obar
                FROM gis_osm_pois_a_free_1 AS obcer, gis_osm_pois_free_1 AS Obar,Parky AS park,hranice_obce_6 AS obce,gis_osm_pois_free_1 AS wc
                WHERE  obce.nm2 LIKE '%'
                AND wc.fclass='toilet'
                AND ST_WITHIN(wc.geom, park.geom)
                AND ST_WITHIN(park.geom, obce.geom)
                AND ST_Area(park.geom::geography) < 5600000
                AND ST_Area(park.geom::geography) > 0
                AND (obcer.fclass='theatre' OR obcer.fclass='fast_food' OR obcer.fclass='restaurant' OR obcer.fclass='cafe' OR obcer.fclass='bar' OR obcer.fclass='playground' OR obcer.fclass='attraction' OR obcer.fclass='theme_park')
                AND ST_WITHIN(obcer.geom, park.geom)
                AND (Obar.fclass='pub' OR Obar.fclass='bar' OR Obar.fclass='nightclub' OR Obar.fclass='cafe' OR Obar.fclass='nightclub')
                AND ST_WITHIN(Obar.geom, obce.geom)
                AND ST_DISTANCE(park.geom::geography,Obar.geom::geography)<500

                //-- Another select generator with coordinates(dlzka,sirka) as input --

                String select = "" +
                "SELECT "+
                showWc + showDistance + showObcerstvenie + showRozloha +
                "obce.nm2 AS cityName,ST_AsGeoJSON(obce.geom) AS city, ST_AsGeoJSON(park.geom) AS parky,park.name AS parkName "+
                "FROM  " +
                fromWc + fromDistance + fromObcerstvenie+
                "Parky AS park,hranice_obce_6 AS obce "+
                "WHERE ST_WITHIN(ST_MakePoint("+dlzka+","+sirka+"),obce.geom) "+
                whereWc+
                "AND ST_WITHIN(park.geom, obce.geom)"+
                whereRozloha+
                whereObcerstvenie+
                whereDistance;


5. Odpoveď z databázy spracujeme a vytvoríme novú odpoveď ako GeoJSON, ktorý rovno na front-ende vložíme do mapbox API volania.
6. Bolo potrebné vytvoriť konvertej GeoJson-u z databázy na GeoJson, ktorý príjma mapbox API.

- Frontend

1. Overíme vstupy - či sú hodnoty zadané
2. Vytvoríme volanie na back-end
3. Po prijatí refreshneme mapu, naplníme tabuľku prijatými dátami a ukážeme notifikáciu o prijatí dát
4. Dáta so zobrazia pomocou niektorej z vytvorených vrstiev:
                       a. Mesto(city)
                       b. Park(park)
                       c. Plaz(beach)
                       d. Obcerstvenie(obcerstvenie)
                       e. Bary a wc(points)
- Frontend

1. Overíme vstupy - či sú hodnoty zadané
2. Vytvoríme volanie na back-end
3. Po prijatí refreshneme mapu, naplníme tabuľku prijatými dátami a ukážeme notifikáciu o prijatí dát
4. Dáta so zobrazia pomocou niektorej z vytvorených vrstiev:
                       a. Mesto(city)
                       b. Park(park)
                       c. Plaz(beach)
                       d. Obcerstvenie(obcerstvenie)
                       e. Bary a wc(points)


## Screenshots
- Záber zobrazujúci bočný panel obsahujúci filter + vyhľadanie oblasti pláže + tabuľu všetkých zaujímavých bodov/oblastí + okolitých barov + detail na bar
  (screenshots/screensho-detail.PNG)
- Záber zobrazujúci bočný panel obsahujúci filter + vyhľadanie oblasti parku a všetkých občerstvení/wc, ktoré sa v ňom nachádzajú + tabuľu všetkých zaujímavých bodov/oblastí +   detail na zaujímavý bod  + okolité bary
  (screenshots/screenshot-park_s_obcerstvenim_aj_wc_aj_okolitymi_barmi.PNG)
- Záber zobrazujúci bočný panel obsahujúci filter + tabuľu všetkých zaujímavých bodov/oblastí +  vyhľadanie oblasti parku podľa kurzora na mape a notifikáciu o prijatých výsledkoch
  (screenshots/screenshot-vyhladanie_podla_kurzora-notifikacia.PNG)

##Implementovanie zaujimave funkcie
- Možnosť kliknutia na body aj polygóny na mape- zobrazenie detailov, realizované pop-upom
- Hľadanie podľa GPS polohy
- Zobrazenie všetkých zaujímavých bodov v tabuľke, pričom po kliknutí na daný bod v tabuľke sa mapa vycentruje na tento bod
- Notifikácia o to, že hľadanie výsledkov bolo dokončené
- Možnosť výberu mesta pomocou pohybovateľného kurzora
- Responzívne otvárateľný filter

## Zdroje dát
- [Vektorové dáta administratívnych území Slovenska] http://wiki.freemap.sk/HraniceAdministrativnychUzemi - bolo otrebné prekonvertovať geom dáta, pomocou konvertera na stránke
- [Zaujimave body a ostatne data] http://wiki.freemap.sk/OpenStreetMap
- [Uploadnute shp súbory] https://drive.google.com/open?id=0B1H7sUvssn2MdEVJU2h1Q1E5SDg
- [Pozadie] https://wallpaperscraft.com/image/park_autumn_foliage_benches_trees_99110_1920x1080.jpg

## Použité nástroje
- Intelij IDEA 2016                  - Back-end
- Visual Studio 2015/Apache-Cordova  - Front-end
- Postgres/Postgis                   - Databáza

## Použité tehnológie
- [Spark] http://sparkjava.com/ (v2.3)
- [Mapbox](http://mapbox.com) (v2.2.2)
- [PostgreSQL](http://www.postgresql.org/) (v9.6)
- [PostGIS](http://postgis.net/) (v2.2.4)
- [Apache/Cordova] Hybridna aplikacia
- [Html/CSS/JS] Bootsrtap, Front-end
- [Java] Back-end (v1.8)
- [PNotify] Notifikacie https://sciactive.com/pnotify/
- [Simple Sidebar] Bočný bar na filter http://startbootstrap.com/template-overviews/simple-sidebar/


<file_sep>import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Exchanger;

/**
 * Created by dvalo on 23.10.2016.
 * Class that keeps method for processing response from database. Convert result to objects.
 */
public class PostgisResponseProcessing {

    static Logger log = Logger.getLogger(PostgisResponseProcessing.class.getName());

    /**
     * Parse response from query and generate new Json for MapBox
     * @param response Response from query to database
     * @return GeoJson for MapBox
     */
    public static String processPostgisResponse( ResultSet response){

        String geoJson = "";
        List<GeoGeometry> responseObjects = new ArrayList<GeoGeometry>();
        Map<String,GeoGeometry> responseObjectsAnyDuplicities = new HashMap<String,GeoGeometry>();
        try {
            String type ="";
            //we have to parse response to objects
            log.info("Processing response  : ");
            while ( response.next() ) {

                JSONObject st_asGeoJson = new JSONObject(response.getString("city"));
                String cityName = null;
                String parkName = null;
                String obcerName = null;
                String wckaName = null;
                String obarName = null;
                String plazName = null;

                try{
                    cityName = response.getString("cityName");
                    processResponse(response,"city",cityName,"",GeoGeometry.MY_TYPE_CITY,responseObjects,responseObjectsAnyDuplicities);
                }catch (Exception e){

                }
                try{
                    parkName = response.getString("parkName");
                    processResponse(response,"parky",parkName,"",GeoGeometry.MY_TYPE_PARK,responseObjects,responseObjectsAnyDuplicities);
                }catch (Exception e){

                }
                try{
                    obcerName = response.getString("obcerName");
                    processResponse(response,"obcerstvenie",obcerName,"",GeoGeometry.MY_TYPE_OBCERSTVENIE,responseObjects,responseObjectsAnyDuplicities);
                }catch (Exception e){

                }
                try{
                    wckaName = response.getString("wcName");
                    processResponse(response,"wcka",wckaName,"",GeoGeometry.MY_TYPE_WC,responseObjects,responseObjectsAnyDuplicities);
                }catch (Exception e){

                }
                try{
                    obarName = response.getString("obarName");
                    processResponse(response,"obar",obarName,"",GeoGeometry.MY_TYPE_OUTSIDE_BAR,responseObjects,responseObjectsAnyDuplicities);
                }catch (Exception e){

                }
                try{
                    plazName = response.getString("plazName");
                    processResponse(response,"plaze",plazName,"",GeoGeometry.MY_TYPE_BEACH,responseObjects,responseObjectsAnyDuplicities);
                }catch (Exception e){

                }
            }
            //we generate geoJson for mapbox according type
            geoJson = GeoJsonMapboxFactory.generateMapBoxJson(responseObjects);
            response.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return geoJson;
    }

    /**
     * Method fill hashmap and list with new Geo object, and method prevent duplicities
     *
     * @param response
     * @param columnGeomName
     * @param name
     * @param description
     * @param myType
     * @param responseObjects
     * @param responseObjectsAnyDuplicities
     */
    private static void processResponse(ResultSet response,String columnGeomName,String name,String description, String myType,List<GeoGeometry> responseObjects,Map<String,GeoGeometry> responseObjectsAnyDuplicities){


        try {
            JSONObject parky = new JSONObject(response.getString(columnGeomName));
            String type = parky.getString("type");
            String coordinatesPark = parky.getJSONArray("coordinates").toString();
            GeoGeometry geoGeometryPark = null;
            if(!responseObjectsAnyDuplicities.containsKey(coordinatesPark)) {
                switch (type) {
                    case GeoPoint.TYPE_POSTGRES:
                        geoGeometryPark = processPointResponse(parky, name, description, myType);
                        break;
                    case GeoMultiLineString.TYPE_POSTGRES:
                        geoGeometryPark = processMultiStringResponse(parky, name, description, myType);
                        break;
                    case GeoPolygon.TYPE_POSTGRES:
                        geoGeometryPark = processPolygonResponse(parky, name, description, myType);
                        break;
                }
                if (geoGeometryPark != null) {
                    responseObjects.add(geoGeometryPark);
                    responseObjectsAnyDuplicities.put(coordinatesPark,geoGeometryPark);
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
    private static GeoPoint processPointResponse(JSONObject st_asGeoJson,String name,String description,String myType){

        GeoPoint geoPoint = null;
        JSONArray coordinateArray = st_asGeoJson.getJSONArray("coordinates");
        geoPoint = new GeoPoint(coordinateArray.toString(),name,description,myType);

        return geoPoint;
    }

    private static GeoMultiLineString processMultiStringResponse(JSONObject st_asGeoJson,String name,String description,String myType){

        GeoMultiLineString geoMultiLineString = null;
        JSONArray coordinateArray = st_asGeoJson.getJSONArray("coordinates");
        geoMultiLineString = new GeoMultiLineString(coordinateArray.toString(),name,description,myType);

        return geoMultiLineString;
    }

    private static GeoPolygon processPolygonResponse(JSONObject st_asGeoJson,String name,String description,String myType){

        GeoPolygon geoPolygon = null;
        String type = st_asGeoJson.getString("type");
        JSONArray coordinateArray = st_asGeoJson.getJSONArray("coordinates");
        geoPolygon = new GeoPolygon(coordinateArray.toString(),name,description,myType);

        return geoPolygon;
    }
}
<file_sep>/**
 * Created by dvalo on 27.11.2016.
 * Class for dynamic generating selects according user inputs
 */
public abstract class SelectFactory {

    private static final String SHOW_WC ="wc.name AS wcName,ST_AsGeoJSON(wc.geom) AS wcka,";
    private static final String FROM_WC ="gis_osm_pois_free_1 AS wc,";
    private static final String WHERE_WC ="AND wc.fclass='toilet' " +
            "AND ST_WITHIN(wc.geom, park.geom) ";

    private static final String SHOW_OBCERSTVENIE ="obcer.name AS obcerName ,obcer.fclass AS obcerClass,ST_AsGeoJSON(obcer.geom) AS obcerstvenie,";
    private static final String FROM_OBCERSTVENIE ="gis_osm_pois_a_free_1 AS obcer,";
    private static final String WHERE_OBCERSTVENIE ="AND (obcer.fclass='theatre' OR obcer.fclass='fast_food' OR obcer.fclass='restaurant' OR obcer.fclass='cafe' OR obcer.fclass='bar' OR obcer.fclass='playground' OR obcer.fclass='attraction' OR obcer.fclass='theme_park') " +
            "AND ST_WITHIN(obcer.geom, park.geom) ";

    private static final String SHOW_DISTANCE ="Obar.name AS obarName ,Obar.fclass AS obarClass,ST_AsGeoJSON(Obar.geom) AS obar,";
    private static final String FROM_DISTANCE ="gis_osm_pois_free_1 AS Obar,";
    private static String getWHERE_DISTANCE(String reqInputVzdialenost){
        return "AND (Obar.fclass='pub' OR Obar.fclass='bar' OR Obar.fclass='nightclub' OR Obar.fclass='cafe' OR Obar.fclass='nightclub') " +
                "AND ST_WITHIN(Obar.geom, obce.geom) " +
                "AND ST_DWITHIN(park.geom::geography,Obar.geom::geography,"+ reqInputVzdialenost +")";
    }

    private static final String SHOW_ROZLOHA ="";
    private static final String FROM_ROZLOHA ="";
    private static  String getWHERE_ROZLOHA(String reqInputMaxRozloha,String reqInputMinRozloha){
        return "AND ST_Area(park.geom::geography) < " + reqInputMaxRozloha + " " +
                "AND ST_Area(park.geom::geography) > " + reqInputMinRozloha + " ";
    }

    /*
    Create select from template. This method create selects for parks.
    Method create selects for request with specified city.
     */
    public static String getSelectTemplate(
            boolean wc,boolean obcerstvenie,boolean rozloha,boolean distance, String placeName, String reqInputVzdialenost,String reqInputMaxRozloha,String reqInputMinRozloha
    ){

        /*
        Skontrolujeme ci nedostavame suradnice namiesto miesta
         */
        if(placeName.contains("MyPoint")){
            return getSelectTemplateFromCircle( wc, obcerstvenie, rozloha, distance,  placeName,  reqInputVzdialenost, reqInputMaxRozloha, reqInputMinRozloha);
        }

        String showWc = "";
        String fromWc = "";
        String whereWc ="";

        String showObcerstvenie = "";
        String fromObcerstvenie = "";
        String whereObcerstvenie ="";

        String showDistance = "";
        String fromDistance = "";
        String whereDistance ="";

        String showRozloha = "";
        String fromRozloha = "";
        String whereRozloha ="";

        if(wc){
            showWc = SHOW_WC;
            fromWc =FROM_WC;
            whereWc = WHERE_WC;
        }
        if(obcerstvenie){
            showObcerstvenie = SHOW_OBCERSTVENIE;
            fromObcerstvenie = FROM_OBCERSTVENIE;
            whereObcerstvenie = WHERE_OBCERSTVENIE;
        }
        if(distance){
            showDistance = SHOW_DISTANCE;
            fromDistance = FROM_DISTANCE;
            whereDistance = getWHERE_DISTANCE(reqInputVzdialenost);
        }
        if(rozloha){
            showRozloha = SHOW_ROZLOHA;
            fromRozloha =FROM_ROZLOHA;
            whereRozloha = getWHERE_ROZLOHA(reqInputMaxRozloha,reqInputMinRozloha);
        }

        //-------Generate select
        String select = "" +
                "SELECT "+
                showWc + showDistance + showObcerstvenie + showRozloha +
                "obce.nm2 AS cityName,ST_AsGeoJSON(obce.geom) AS city, ST_AsGeoJSON(park.geom) AS parky,park.name AS parkName "+
        "FROM  " +
                fromWc + fromDistance + fromObcerstvenie+
                "Parky AS park,hranice_obce_6 AS obce "+
        "WHERE  obce.nm2 LIKE '"+placeName+"%' "+
                whereWc+
        "AND ST_WITHIN(park.geom, obce.geom)"+
                whereRozloha+
                whereObcerstvenie+
                whereDistance;

        return select;
    }

    /*
      Create select from template. This method create selects for beach.
      Method create selects for request with specified city.
   */
    public static String getSelectTemplateForBeach(
            boolean wc,boolean obcerstvenie,boolean rozloha,boolean distance, String placeName, String reqInputVzdialenost,String reqInputMaxRozloha,String reqInputMinRozloha
    ){

        /*
        Skontrolujeme ci nedostavame suradnice namiesto miesta
         */
        if(placeName.contains("MyPoint")){
            return getSelectTemplateForBeachFromCircle( wc, obcerstvenie, rozloha, distance,  placeName,  reqInputVzdialenost, reqInputMaxRozloha, reqInputMinRozloha);
        }

        String showWc = "";
        String fromWc = "";
        String whereWc ="";

        String showObcerstvenie = "";
        String fromObcerstvenie = "";
        String whereObcerstvenie ="";

        String showDistance = "";
        String fromDistance = "";
        String whereDistance ="";

        String showRozloha = "";
        String fromRozloha = "";
        String whereRozloha ="";

        if(wc){
            showWc = SHOW_WC;
            fromWc =FROM_WC;
            whereWc = WHERE_WC;
        }
        if(obcerstvenie){
            showObcerstvenie = SHOW_OBCERSTVENIE;
            fromObcerstvenie = FROM_OBCERSTVENIE;
            whereObcerstvenie = WHERE_OBCERSTVENIE;
        }
        if(distance){
            showDistance = SHOW_DISTANCE;
            fromDistance = FROM_DISTANCE;
            whereDistance = getWHERE_DISTANCE(reqInputVzdialenost);
        }
        if(rozloha){
            showRozloha = SHOW_ROZLOHA;
            fromRozloha =FROM_ROZLOHA;
            whereRozloha = getWHERE_ROZLOHA(reqInputMaxRozloha,reqInputMinRozloha);
        }

        //-------Generate select
        String select = "" +
                "SELECT "+
                showWc + showDistance + showObcerstvenie + showRozloha +
                "obce.nm2 AS cityName,ST_AsGeoJSON(obce.geom) AS city, ST_AsGeoJSON(park.geom) AS plaze,park.name AS plazName "+
                "FROM  " +
                fromWc + fromDistance + fromObcerstvenie+
                "gis_osm_natural_a_free_1 AS park,hranice_obce_6 AS obce "+
                "WHERE  obce.nm2 LIKE '"+placeName+"%' "+
                "AND park.fclass='beach'"+
                whereWc+
                "AND ST_WITHIN(park.geom, obce.geom)"+
                whereRozloha+
                whereObcerstvenie+
                whereDistance;


        return select;
    }

    /*
      Create select from template. This method create selects for parks.
      Method create selects for request with coordinates(dlzka,sirka) as input.
      For example, from current GPS location or cursor on the map.
   */
    public static String getSelectTemplateFromCircle(
            boolean wc,boolean obcerstvenie,boolean rozloha,boolean distance, String placeName, String reqInputVzdialenost,String reqInputMaxRozloha,String reqInputMinRozloha
    ){

        String dlzka ="0";
        String sirka= "0";

        placeName = placeName.replaceAll("MyPoint","");
        dlzka = placeName.split(",")[0];
        sirka = placeName.split(",")[1];

        String showWc = "";
        String fromWc = "";
        String whereWc ="";

        String showObcerstvenie = "";
        String fromObcerstvenie = "";
        String whereObcerstvenie ="";

        String showDistance = "";
        String fromDistance = "";
        String whereDistance ="";

        String showRozloha = "";
        String fromRozloha = "";
        String whereRozloha ="";

        if(wc){
            showWc = SHOW_WC;
            fromWc =FROM_WC;
            whereWc = WHERE_WC;
        }
        if(obcerstvenie){
            showObcerstvenie = SHOW_OBCERSTVENIE;
            fromObcerstvenie = FROM_OBCERSTVENIE;
            whereObcerstvenie = WHERE_OBCERSTVENIE;
        }
        if(distance){
            showDistance = SHOW_DISTANCE;
            fromDistance = FROM_DISTANCE;
            whereDistance = getWHERE_DISTANCE(reqInputVzdialenost);
        }
        if(rozloha){
            showRozloha = SHOW_ROZLOHA;
            fromRozloha =FROM_ROZLOHA;
            whereRozloha = getWHERE_ROZLOHA(reqInputMaxRozloha,reqInputMinRozloha);
        }

        //-------Generate select
        String select = "" +
                "SELECT "+
                showWc + showDistance + showObcerstvenie + showRozloha +
                "obce.nm2 AS cityName,ST_AsGeoJSON(obce.geom) AS city, ST_AsGeoJSON(park.geom) AS parky,park.name AS parkName "+
                "FROM  " +
                fromWc + fromDistance + fromObcerstvenie+
                "Parky AS park,hranice_obce_6 AS obce "+
                "WHERE ST_WITHIN(ST_MakePoint("+dlzka+","+sirka+"),obce.geom) "+
                whereWc+
                "AND ST_WITHIN(park.geom, obce.geom)"+
                whereRozloha+
                whereObcerstvenie+
                whereDistance;


        return select;
    }

    /*
          Create select from template. This method create selects for beach.
          Method create selects for request with coordinates(dlzka,sirka) as input.
          For example, from current GPS location or cursor on the map.
       */
    public static String getSelectTemplateForBeachFromCircle(
            boolean wc,boolean obcerstvenie,boolean rozloha,boolean distance, String placeName, String reqInputVzdialenost,String reqInputMaxRozloha,String reqInputMinRozloha
    ){

        String dlzka ="0";
        String sirka= "0";

        placeName = placeName.replaceAll("MyPoint","");
        dlzka = placeName.split(",")[0];
        sirka = placeName.split(",")[1];

        String showWc = "";
        String fromWc = "";
        String whereWc ="";

        String showObcerstvenie = "";
        String fromObcerstvenie = "";
        String whereObcerstvenie ="";

        String showDistance = "";
        String fromDistance = "";
        String whereDistance ="";

        String showRozloha = "";
        String fromRozloha = "";
        String whereRozloha ="";

        if(wc){
            showWc = SHOW_WC;
            fromWc =FROM_WC;
            whereWc = WHERE_WC;
        }
        if(obcerstvenie){
            showObcerstvenie = SHOW_OBCERSTVENIE;
            fromObcerstvenie = FROM_OBCERSTVENIE;
            whereObcerstvenie = WHERE_OBCERSTVENIE;
        }
        if(distance){
            showDistance = SHOW_DISTANCE;
            fromDistance = FROM_DISTANCE;
            whereDistance = getWHERE_DISTANCE(reqInputVzdialenost);
        }
        if(rozloha){
            showRozloha = SHOW_ROZLOHA;
            fromRozloha =FROM_ROZLOHA;
            whereRozloha = getWHERE_ROZLOHA(reqInputMaxRozloha,reqInputMinRozloha);
        }

        //-------Generate select
        String select = "" +
                "SELECT "+
                showWc + showDistance + showObcerstvenie + showRozloha +
                "obce.nm2 AS cityName,ST_AsGeoJSON(obce.geom) AS city, ST_AsGeoJSON(park.geom) AS plaze,park.name AS plazName "+
                "FROM  " +
                fromWc + fromDistance + fromObcerstvenie+
                "gis_osm_natural_a_free_1 AS park,hranice_obce_6 AS obce "+
                "WHERE ST_WITHIN(ST_MakePoint("+dlzka+","+sirka+"),obce.geom) "+
                "AND park.fclass='beach'"+
                whereWc+
                "AND ST_WITHIN(park.geom, obce.geom)"+
                whereRozloha+
                whereObcerstvenie+
                whereDistance;


        return select;
    }
    }
<file_sep>import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dvalo on 23.10.2016.
 * Class for geometry Point, keeps attributes like name,description,myType(city,park,..),icon,coordinatesList
 */
public class GeoPolygon implements GeoGeometry{

    public static final String TYPE_POSTGRES = "MultiPolygon";
    public static final String TYPE_MAPBOX = "Polygon";
    private String name = "\"\"";
    private String description = "\"\"";
    private String myType = "\"\""; //this can be park/beach whatever
    private String icon = "\"\"";

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = "\""+icon+"\"";
    }

    private List<Coordinate> coordinatesList = new ArrayList<Coordinate>();

    static Logger log = Logger.getLogger(GeoPolygon.class.getName());

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name != null) this.name = "\""+name+"\"";
    }

    public String getDescription() {
        String rtrn = " <h4>Title: "+name.replaceAll("\"","")+
                " </h4><p>Description: "+description.replaceAll("\"","")+
                " Druh: "+myType.replaceAll("\"","")+"</p>";

        return "\""+rtrn+"\"";
    }

    public void setDescription(String description) {
        this.description = "\""+description+"\"";
    }

    public String getMyType() {
        return myType;
    }

    public void setMyType(String myType) {

        this.myType = "\""+myType+"\"";
        switch (myType){
            case(GeoGeometry.MY_TYPE_PARK):
                setIcon(GeoGeometry.MY_TYPE_ICON_PARK);
                break;
            case(GeoGeometry.MY_TYPE_WC):
                setIcon(GeoGeometry.MY_TYPE_ICON_WC);
                break;
            case(GeoGeometry.MY_TYPE_BEACH):
                //setIcon(GeoGeometry.MY_TYPE_ICON_);
                break;
        }
    }

    public GeoPolygon(String coordinatesPlainText,String name,String description,String myType) {

        setName(name);
        setDescription(description);
        setMyType(myType);
        coordinatesPlainText = coordinatesPlainText.substring(2,coordinatesPlainText.length()-2);
        //log.info("Polygon Plain Text: "+coordinatesPlainText);
        String[] coordinates = coordinatesPlainText.split("],");
        for(String coord: coordinates){
            Coordinate coordinate = new Coordinate(coord);
            addCoordinate(coordinate);
        }
    }
    @Override
    public String generateGeoJsonMapbox() {

        //generate geometry
        String geoJsonGeometry = "";
        geoJsonGeometry = "{"+
                TYPE_TEXT+": "+"\""+ TYPE_MAPBOX +"\","+
                COORDINATES_TEXT+": [[";

        StringBuilder builder =new StringBuilder();
        for(int i=0;i<coordinatesList.size();i++){
            builder.append( coordinatesList.get(i).getCoordinate());
            if(i!=coordinatesList.size()-1)builder.append(",");
        }
        geoJsonGeometry+=builder.toString();
        geoJsonGeometry += "]]"+
                "}";

        //generate properties
        String geoJsonProperties = "";
        geoJsonProperties = PROPERTIES_TEXT+": {"+
                TITLE_TEXT+": "+name+","+
                NAME_TEXT+": "+getDescription()+","+
                TITLE_DECRIPTION+": "+getDescription()+","+
                MY_TYPE_TEXT+": "+myType+","+
                ICON_TEXT+": "+icon+
                "},";
        //generate rest of polygon
        String geoJson = "{"+
                GeoGeometry.TYPE_TEXT+": "+GeoGeometry.TYPE_FEATURE+","
                +geoJsonProperties
                +GeoGeometry.GEOMETRY_TEXT+": "
                +geoJsonGeometry
                +"}";


        return geoJson;
    }

    public List<Coordinate> getCoordinatesList() {
        return coordinatesList;
    }

    public void setCoordinatesList(List<Coordinate> coordinatesList) {
        this.coordinatesList = coordinatesList;
    }

    public void addCoordinate(Coordinate coordinate) {
        this.coordinatesList.add(coordinate);
    }

    public void removeCoordinate(Coordinate coordinate) {
        this.coordinatesList.remove(coordinate);
    }

    @Override
    public String getPostgresType() {
        return TYPE_POSTGRES;
    }

    @Override
    public String getMapBoxType() {
        return TYPE_MAPBOX;
    }
}
<file_sep>import org.apache.log4j.Logger;

/**
 * Created by dvalo on 22.10.2016.
 * Class for geometry Point, keeps attributes like name,description,myType(city,park,..),title,coordinate
 */
public class GeoPoint implements GeoGeometry{

    static Logger log = Logger.getLogger(GeoPoint.class.getName());
    public static final String TYPE_POSTGRES = "Point";
    public static final String TYPE_MAPBOX = "Point";

    private String name = "\"\"";
    private String description = "\"\"";
    private String myType = "\"\""; //this can be park/beach whatever
    private String title = "\"\"";
    private String icon = "\"\"";

    private Coordinate coordinate;

    public GeoPoint(String coordinates,String name,String description,String myType) {

        setName(name);
        setDescription(description);
        setMyType(myType);
        this.coordinate = new Coordinate(coordinates);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {

        if(name != null){
            name=name.replaceAll("\"","");
            this.name = "\""+name+"\"";
        }
    }

    public String getDescription() {

        String rtrn = " <h4>Title: "+name.replaceAll("\"","")+
                " </h4><p>Description: "+description.replaceAll("\"","")+"</br>"+
                " Druh: "+myType.replaceAll("\"","")+"</br>"+
                " GPS coordinates: "+coordinate.getX()+" "+coordinate.getY()+"</br>"+
                "</p>";

        return "\""+rtrn+"\"";
    }

    public void setDescription(String description) {
        this.description = "\""+description+"\"";
    }

    public String getMyType() {
        return myType;
    }

    public void setMyType(String myType) {

        this.myType = "\""+myType+"\"";
        switch (myType){
            case(GeoGeometry.MY_TYPE_PARK):
                setIcon(GeoGeometry.MY_TYPE_ICON_PARK);
                break;
            case(GeoGeometry.MY_TYPE_WC):
                setIcon(GeoGeometry.MY_TYPE_ICON_WC);
                break;
            case(GeoGeometry.MY_TYPE_BEACH):
                //setIcon(GeoGeometry.MY_TYPE_ICON_);
                break;
        }
    }

    public String getPostgresType() {
        return TYPE_POSTGRES;
    }

    @Override
    public String getMapBoxType() {
        return TYPE_MAPBOX;
    }

    public Coordinate getCoordinate() {
        return coordinate;
    }

    public void setCoordinate(Coordinate coordinate) {
        this.coordinate = coordinate;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = "\""+icon+"\"";
    }

    @Override
    public String generateGeoJsonMapbox() {
        String geoJson = "";

        geoJson = "{"+
                TYPE_TEXT+": "+TYPE_FEATURE+","+
                GEOMETRY_TEXT+": {"+
                    TYPE_TEXT+": "+"\""+ TYPE_MAPBOX +"\","+
                    COORDINATES_TEXT+": "+coordinate.getCoordinate()+
                "},"+
                PROPERTIES_TEXT+": {"+
                    TITLE_TEXT+": "+name+","+
                    TITLE_DECRIPTION+": "+getDescription()+","+
                    ICON_TEXT+": "+icon+","+
                    MARKER_SYMBOL_TEXT+": "+icon+","+
                    MY_TYPE_TEXT+": "+myType+
                "}"+
                "}";

        return geoJson;
    }
}
<file_sep>import org.apache.log4j.Logger;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.UUID;

import static spark.Spark.port;

/**
 * Created by dvalo on 21.10.2016.
 * Main class for application. We are setting port for Spark framework here.
 */
public class Main {

    static Logger logger = Logger.getLogger(Main.class.getName());

    public static void main(String[] args) {

        port(4567);

        String id;
        try {
            id = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e1) {

            id = UUID.randomUUID().toString();
            e1.printStackTrace();
        }

        try {

            logger.info("Starting mapnode on port 4567 with " + id);
            new PostgreSQLJDBC();
            new MapApiController();
        } catch(Exception e) {
            e.printStackTrace();
            logger.fatal("Cannot initialize mapnode, exiting...");
            return;
        }
    }

}
