Connection between PostGIS and QGIS

GIS applications are tools that allow users to create interactive queries (user-created searches), analyze spatial information, edit data in maps, and present the results of all these operations. Geographic information science is the science underlying geographic concepts, applications, and systems and What goes beyond a GIS is a spatial data infrastructure, a concept that has no such restrictive boundaries. For handling the spatial data infrastructure we use tools like PostGIS and QGIS. this post will help guides you about How can we establish a Connection between PostGIS and QGIS with the help of some GIS operations.

Connection between PostGIS and QGIS

PostGIS and QGIS are two major platforms used for handling GIS operations. PostGIS adds support for geographic objects allowing location queries to be run in SQL. As PostGIS is a spatial database extender for PostgreSQL object-relational database. In our previous post you can read about PostGIS and PostgreSQL.

Now we are going the discuss the details of how We can establish connection between PostGIS and QGIS and before that let’s just discuss some important topics in brief.

QGIS

QGIS is one of the most common open source application used by GIS analyst, Geographers, Civil Engineers and many other professionals. QGIS is a Desktop based Geographic Information System (GIS) Application for creating maps, editing, viewing and analyzing Geospatial data. Quantum GIS is a cross-platform, free and open source application. It can be run on multiple operating system like Mac OS X, Windows, Ubuntu, Linux and Unix.

PostGIS

PostGIS is an open source software program that adds support for geographic objects to the PostgreSQL object-relational database. PostGIS follows the Simple Features for SQL specification from the Open Geospatial Consortium (OGC).
Technically PostGIS was implemented as a PostgreSQL’s extension. And There are a large number of software products that can use PostGIS as a database backend.

PostgreSQL

PostgreSQL is an open source relational database management system ( DBMS ) developed by a worldwide team of volunteers. PostgreSQL is not controlled by any corporation or other private entity and the source code is available free of charge.
When we installed PostgreSQL database server, the PostgreSQL installer also installed some useful tools for working with the database server. You can connect to the PostgreSQL database server by using the psql or pgAdmin tool.
psql is an interactive terminal program provided by PostgreSQL. You can do a lot with psql tool e.g., execute SQL statements, manage database objects, etc. and The second way to connect to a database is using pgAdmin GUI application. By using pgAdmin GUI application, you can interact with PostgreSQL database server via an intuitive user interface.

Connection between PostGIS and QGIS

  • Import Shapefile into PostGIS

    Connection between PostGIS and QGIS
    Connection between PostGIS and QGIS

    We are going to import some Shapefiles into PostGIS for creating a table in PostgreSQL database. Importing shapefiles into PostGIs using psql is already discussed in our previous post “Import Shapefile in Postgresql – shp2pgsql”.
    Shapefile: The most popular geospatial vector data format. First developed by ESRI. Because of it’s open specification it is now predominantly used to share GIS data between open source and proprietary software.
    We can also do this import with pgShapeloader tool (also known as “PostGIS Shapefile Import/Export Manager” or “PostGIS Shapefile and DBF loader”). It provides another option for loading shapefiles into PostGIS database tables. It is the graphical user interface (GUI) equivalent of the command line shp2pgsql tool.
    The pgShapeloader tool combines the two data loading stages, converting data into SQL commands and running those commands against the target database, into one operation.
    On Linux pgShapeloader can be launched from the terminal with the shp2pgsql-gui command which generates this.

    now click View connection details and enter the connection information in the PostGIS Connection section.

    Click OK to return to the main application. The shapefile loader uses the supplied connection details to connect to the target database; the connection status is reported in the Log Window.
    Connection between PostGIS and QGIS

    To select your source files, click Add File to open the Select a Shape File dialog box. Navigate to the location of your shapefile, click the shapefile you wish to load, and click Open. Multiple files can also be added in the same way. and Once all import options have been added and configured, click OK and click Import to start the conversion.
    Connection between PostGIS and QGIS

    Now these shape files are added in the PostGIS databases as tables you can view them and their attributes in pgAdmin or psql.
    Connection between PostGIS and QGIS

  • Add and Modify PostGIS data files in QGIS

    Now we are going to add and modify the PostGIS database files in QGIS application.

    • Open QGIS application, you will see PostGIS option in Browser toolbar here.
      Connection between PostGIS and QGIS
    • Right click on the PostGIS option and click on the “New Connection” that will open a “Create a New PostGIS connection” toolbar.

      Connection between PostGIS and QGIS
      Connection between PostGIS and QGIS
    • Enter the Database Connection details and then click the “Test Connection” button. this button will open up an authentication form for server details. fill the authentication details and click Ok.
      Connection between PostGIS and QGIS
    • you will see a message on toolbar i.e connection to is successful. Now click OK and you have successfully connected your database with the QGIS. You can see the Database and the Shapefiles we imported in PostGIS below the PostGIS in browser window in QGIS.
      Connection between PostGIS and QGIS
    • Now for adding these Shapefile as layers in QGIS, Right click on the files and select “Add Selected layers to Canvas” then the file will show as a layer on canvas and in layers window in QGIS. you can also see the attributes of the Shapefile  by right-click on the filename in Layers window and selecting Open attribute table.
      Connection between PostGIS and QGIS
    • Now for Modifying the Shapefiles , I prefer you to go to Split Sub Divide polygon layer using QGIS – Shapefile, kml, GeoJson.
      There you can modify the Shapefile and we can see that as the polygon is Sub-divided It increases the attributes of the Shapefile.
  • Now as we can see that the attributes of Shapefile after modifying has increased compare to the attributes when the file was imported from PostGIS database.

When the Shapefile is saved after modification in QGIS by default the file is also saved in PostGIS database with the new and changed attributes it has before.

The connection between QGIS and PostGIS is proves that if any data file is altered in QGIS, the file also gets modified in the PostGIS database system.

Download free Shapefile Maps

This is how we can show the establishment of the Connection between PostGIS and QGIS.

Import OSM data in Postgis – OSM2pgsql

This article lets you know how to import data in postgresql.  Open Street map (OSM) is open and free data. Anyone one can download this data. It mainly contains point data, line data, polygon data and geometry information. Data contains much information and becomes heavy i.e. upto 30GB or more. Many compression techniques are applied to make it available to user in minimum size.

Install osm2pgsql- Import OSM data in Postgis

This utility can be installed using command prompt. Follow the command,

--> apt-get install osm2pgsql

Now you can see the options available with the command. Type osm2pgsql in command prompt. You will get the following result.

Import OSM data in Postgis- OSM2pgsql

We know that you import data in database we must create a database for storing tables. You can download and install postgresql with our previous tutorial Install PostGIS and PostgreSQL in Linux Ubuntu 16.4 

Here we have database ‘potsgres’ in Postgresql with a user. In the command we specify option -s is slim mode,Store temporary tables in database. This allows incremental updates using diff files also available at OSM data servers, and reduces memory usage at a cost in disk space and import time. This mode of operation is recommended.  The option -G Generate multi-geometry features in PostgreSQL tables. Option -U is user available in Postgresql, -W  prompts for password and in the last give file name.

As files are heavy in size so this process takes time.

Import OSM data in Postgis- OSM2pgsql
Import OSM data in Postgis

This Open street map data is also available in pbf format (Protocolbuffer Binary Format). This format is specially designed to compress data. This is much faster than gzipped and bzipped planet while reading files.

The data available is in data.osm.pbf format so we need to extract this data first. This can be done with osmconvert command. Type osmconvert in command prompt, if not available install this with given command.

–>sudo apt-get install osmctools

Now use the following command to convret data in osm,

–>osmconvert Input.pbf > output.osm

After this check for the OSM file in folder. Now use the command given for importing data in postgresql.

Import OSM data in Postgis- OSM2pgsql

Output

This output can be seen in postgresql available in table format.

Import OSM data in Postgis- OSM2pgsql
Import OSM data in Postgis

In this way you can also import shapefile data in postgresql. You can also try out conversion using GDAL utilities as shapefile to sql, shapefile to mif etc.

Please let us know if you need any help by commenting in given comment box.

Geographical Information System (GIS) FAQs – GIS Interview Question

Geographical Information System (GIS) is a computer-based tool that is designed to capture, store, manipulate, analyze, manage, and present spatial or Geographic data, usually in a map. GIS application is a tool that allows users to create user-created searches, integrate and analyze spatial information and present the results of all these operations. GIS describes any information system that integrates, edits, analyzes, shares, and displays geographic information. GIS technologies are using digital information, for which various digitized data creation methods are used. Here in this post we will check FAQs of Geographical Information System (GIS) and Common Question asked during Interview Question.

GIS Interview Question – Frequently Asked Question GIS

Que. What is GIS?
Ans. GIS is a blend of S/W and H/W used to collect, manipulate analyst and produce geographical data

Que. What is the difference between geo-coding and geo-referencing?
Ans. Geo-coding is when you associate a place name or an address with map coordinates. Geo-referencing is the process of associating plain digital images taken from a satellite or a plane with map coordinates so that they can be overlaid on street maps.

Que. Name the two data structures that have the capacity to hold spatial data.
Ans. The two data structures that can hold spatial data include raster and vector.

Que. Differentiate between GIS commands and tools?
Ans. Commands do not require interaction with the map, they just rely on surface. Tools on the other hand require interaction with the map canvas.

Que. Name applications of the Arc GIS desktop.
Ans. Arc Map, Arc catalog and Arc toolbox.

Que. Define remote sensing?
Ans. Remote sensing refers to detection and classification of objects on or in earth without physical contact, generally attained through aerial sensors.

Que. What is the role of GPS in GIS?
Ans. Competent decisions can only be rendered by reliable data and though GIS is an amazing data management tool, using it with GPS helps in validating the data analysis and results.

Que. What is a globe?
Ans. A sphere shaped model of the Earth

Que. What are the 7 large land massses found on a globe called?
Ans. Continents

Que. Name the 7 continents.
Ans. Asia, Africa, Europe, North America, South America, Antarctica, and Australia.

Que. Latitude and Longitude are measured in ____ .
Ans. Degrees

Que. What does the  scale on a map shows?
Ans. Where you are,How the size of the map relates to the size of a real place and direction as North,east,south,west.

Que. What does the legend or map key tell?
Ans. Direction, What the symbols on the map mean and The distance between the equator and a point north or south on the earth’s surface

Que. What is GPS ?
Ans. Global Positioning System(GPS) is a space based satellite navigation system that provides location and time information in all the weather conditions, anywhere on or near the earth.

Que. List the satellite navigation systems ?
Ans. The navigation systems are as follows:

  1. GLONASS(Globalnaya navigatsionnaya sputnikovaya sistema) : Russia’s global navigation system.
  2. IRNSS ( Indian Regional Navigational Satellite System),  COMPASS : People’s republic of china’s global system.

Que. Explain briefly the working principle of GPS ?
Ans. A Global Positioning System’s receiver calculates its position by precisely timing the signals sent by Global Positioning System satellite high above the earth. These distances and satellite location are used to compute the location of the receiver using the Navigation Equations. Although 4 satellites are required for normal operation, fewer apply in special cases.

Que. Explain the structure of GPS ?
Ans. The structure of GPS have three main segments. These are as follows: Page segment, Control segment and User segment

Que. Explain the space segment of GPS ?
Ans. Space segment is composed of 24 to 32 satellites in medium Earth orbit and also includes the payload adapter to the boosters required to launch them into orbit.

Que. Explain the control segment of GPS ?
Ans. Control segment is composed of a master control station , an alternate master control station, and a host of dedicated and shared ground antennas and monitor stations.

Que. Explain the user segment of GPS?
Ans. User segment is composed of thousands of U.S and allied military users of the secure GPS Precise positioning service and millions of civil and scientific users of the standard positioning service.

Que. What Is Gps Rollover?
Ans. This document contains information about GPS Week 1024 Rollover.

Que. What Is The Status Of Selective Availability (sa)?
Ans. Effective as of Midnight 01 May 2000, Selective Availability has been set to zero

Que. Explain Portable Gps?
Ans. Although any small global positioning system could be referred to as a portable GPS, the term generally refers to those units which give driving directions and are meant to be mounted in cars. Others, used for outdoor activities, are generally referred to as handheld GPS units. Still, there could be some times when the terms are confused and a portable GPS and handheld GPS are synonymous.

Que. What’s The Status Of The Gps?
Ans. The Global Positioning System reached full Operational Capability (FOC) on July 17, 1995

Que. What is a project (.mxd) file?
Ans. You can think of a project file as a database management tool. GIS users often must work on the same files for long periods of time, and the .mxd file is the management file that remembers which files you use, where they are located, the projection the file is stored in, the colors you have set, etc.

Que. What is a shapefile?
Ans. Shapefiles are computer files that produce images for users in a GIS environment. There are three basic types of shapefiles: line poin and polygon.

Que. How do I prepare spatial data for use with ArcGIS?
Ans. If you have data with spatial locators (e.g., census FIPS codes, zip codes, street addresses, etc.), you can link your data to shapefiles within a GIS environment. Furthermore, you can join tables in a GIS project.

Que. What are ArcMap, ArcCatalog and ArcToolbox?
Ans. ArcMap is the application in ArcGIS that you use to create, visualize, and manipulate maps, whereas ArcCatalog is the application in ArcGIS that you use for browsing and organizing data files. ArcToolbox is the application in ArcGIS that contains data management and conversion tools and wizards (e.g., projection tools).

Que. What are some of the functions of the Spatial Analyst extension?
Ans. The Spatial Analyst extension can help you find slopes and directions, least cost paths, and best locations for a new facility based on multiple criteria. This is useful for analyzing raster data as well as feature data.

Que. What are some of the functions of the Geostatistical Analyst extension?
Ans. The Geostatistical Analyst extension can help you with the production of statistical surfaces for exploratory spatial data analysis, structural analysis (calculating properties of neighboring areas), and surface prediction and results analysis.

Que. Is there any way to change or expand existing ArcGIS functionality?
Ans. ESRI makes a number of scripts and other downloads available for users. Scripts work with the existing software to extend functionality or to automate common tasks. The scripts on ESRI’s site come from both ESRI itself and from other ArcGIS users; you can even upload your own scripts for other people to download.

Que. How do you edit a project (.mxd) file? Why do you need to edit a project file?
Ans. Once you open your project file, editing is simple. The last saved version of your files will appear on your computer screen, and you can manipulate the existing settings to update the file. (Always remember to save it!) Project files must be edited in order for changes to be reflected in your work. You often work on GIS projects over long periods of time, and as you work, new data, shapefiles, etc. can be added to keep your project current.

Que. What is the MSD file and can I edit it?
Ans. The map service definition (MSD) file is a new file used by the fast map service drawing engine introduced at ArcGIS Server 9.3.1. The MSD file always starts with an MXD map document. You use the Map Service Publishing Toolbar to analyze your MXD in ArcMap. Once you’ve addressed issues returned by the analysis, you use the same toolbar to either publish the service or save the MSD file.

Que. How does GPS device work?
Ans. The orbits are arranged so that at any time, anywhere on Earth, there are at least four satellites “visible” in the sky. A GPS receiver’s job is to locate four or more of these satellites, figure out the distance to each, and use this information to deduce its own location.

Que. What is Selective Availability (SA)?
Ans. SA was a technique implemented by the DOD to intentionally degrade a user’s navigation solution. The single largest source of error for SPS users was SA. The net result of SA was about a five-fold increase in positioning error. DOD achieved signal degradation by altering (also known as dithering) the satellite clock. Another means designed by DOD to degrade GPS performance was to broadcast less accurate ephemeris parameters.

Que. Why was SA Necessary?
Ans. SA was used to protect the security interests of the U.S. and its allies by globally denying the full accuracy of the civil system to potential adversaries.

Que. Will SA ever be turned back on?
Ans. It is not the intent of the U.S. to ever use SA again. To ensure that potential adversaries to do not use GPS, the military is dedicated to the development and deployment of regional denial capabilities in lieu of global degradation through SA.

Que. What kind of orbits are the GPS satellites in?
Ans. The GPS satellites operate in circular 10,900nm (20,200km) 12-hour orbits at an inclination of 55 degrees. They are not in geo-stationary orbit.
How vulnerable are GPS satellites to jamming and interference?
GPS satellite signals, like any other navigation signals, are subject to some form of interference. The FAA is actively working with the U.S. Department of Defense and other U.S. Government Agencies to detect and mitigate these effects and make sure that the GPS and any related augmentation systems are available for safe aviation operations. As with all navigation aids, interference, whether intentional or unintentional, is always a concern.

Que. Is the basic GPS signal sufficient to meet all the needs of civil aviation?
Ans. This is not a simple yes/no answer. The answer is that it depends on the service requirements of each user or aviation authority. For many countries, GPS supplies a better capability than the existing ground-based systems or lack thereof. Yet for other countries with large infrastructures, the GPS signal does not meet the accuracy, integrity, availability, and continuity requirements critical to safety of flight. Enhancements to the Global Positioning System (GPS) such as the Wide Area Augmentation System (WAAS) and Ground Based Augmentation System (GBAS) provide the necessary corrections for meeting safety-of-life flight requirements.

Que. What is Differential GPS (DGPS)?
Ans. In the basic form of DGPS, the position of a reference receiver at a monitoring or reference station is surveyed in, that is, its position is known accurately. The user receiver should be no more than about 300 miles away from the reference receiver which makes pseudorange measurements, just as any user receiver would. However, because the reference receiver knows its position accurately, it can determine “biases” in its pseudorange measurements. For each satellite in view of the reference receiver, these biases are computed by differencing the pseudorange measurement and the satellite-to-reference receiver geometric range. These biases incurred in the pseudorange measurement process include errors arising from ionospheric delay, tropospheric delay, and satellite clock offset from GPS time. For real-time applications, the reference station transmits these biases, called differential corrections, to all users in the coverage area of the reference station. Users incorporate these corrections to improve the accuracy of their position solution.

Que. Will the GPS tracking system make the fleet management easier?
Ans. Fleet management involves managing vehicles and personnel available. It also constitutes route planning, route optimization, personnel management, asset tracking, vehicle maintenance, report generation, fuel management, etc.

Que. What are the gains of implementing student GPS tracking system?
Ans. You need to be clear about the potential gains of installing a vehicle tracker in the school buses before you start out on a GPS tracking system. Is it truly worth the cost and effort? Does it provide what it promises to offer? You should also consider getting a detailed demo run so that you will be able to understand the functioning of the system.

Que. Do you need a cost effective solution for vehicle fleet management?
Ans. The budget for each school to implement an effective solution would definitely vary. For this reason, you should consider the number of vehicles, data base needed (e.g. up to street level), additional facilities required, such SMS or PUSH notification facilities, etc. It should be decided whether all the features offered in a system is actually useful for you. There are advanced systems which even offer guided voice directions to make school bus trips less cumbersome for bus drivers and attendants.

Que. What is the potential for a gap in GPS service?
Ans. The Air Force is confident GPS will continue to meet existing service commitments. Several years ago, the Air Force recognized the potential for an availability gap and took action to institutionalize procedures and processes to mitigate the potential gap or minimize any impact. Air Force Space Command developed key processes within the operational community as well as the acquisition community to extend the life of on-orbit assets and to ensure capability is delivered in a timely manner. Users can employ GPS with confidence today and continue to do so in the future. As identified by the General Accounting Office (GAO) in testimony to Congress, “There have been times before where people have worried about gaps and the Air Force has managed them quite successfully.”

Que. Is GPS under U.S. military control?
Ans. Though acquired and operated by the Department of Defense, GPS is a multi-use system owned by the United States Government and paid for by the U.S. taxpayer. The outstanding performance of GPS over decades has earned the confidence of millions of civil and military users worldwide. The management structure and modernization efforts directed by U.S. policy continue this support for multi-user applications. Any misperceptions will be overcome as they have in the past, by a demonstrated record of service and performance to all users.

Que. What are the benefits of GPS tracking?
Ans. GPS tracking tells you which employees are on the clock and where they’re located. You’ll be able to see who is closest to a customer when scheduling a new job on the fly, more effectively manage employees at various locations, identify inefficiencies in workloads and routes, and build trust by adding accountability safeguards that benefit everyone.

Que. How accurate is the GPS location data from the GPS device?
Ans. Different GPS devices offer differing levels of accuracy so always ask the question. AVS GPS devices have a high level of GPS accuracy of between 5 and 10 metres or better with clear skies.

Que. What is a GPS locator?
Ans. A GPS locator does not record regular position updates, it will only log its position on command. Simply send a TXT to the tracker and it will TXT back its’ location. Some GPS locators will send GPS co-ordinates (Latitude and Longitude) which can then be entered into Google to bring up a map.

Que. What are the limitations of GPS tracking?
Ans. GPS tracking is not invincible and no GPS hardware will be able to guarantee position logs 100% of the time. GPS devices rely on being able to communicate with the satellites in space and so in highly built up areas or underground carparks reception can be blocked.

Que. What is GPS tracking?
Ans. GPS tracking is a way of determining the location of a vehicle, person or other asset. A GPS device is attached to, or installed into, the asset you wish to track. The device then uses the Global Positioning System to record the position of the asset at regular intervals.

Que. what is trilateration?
Ans. A GPS receiver uses trilateration (a more complex version of triangulation) to determine its position on the surface of the earth by timing signals from three satellites in the Global Positioning System.

Que. What is the difference between triangulation and Trilateration?
Ans. As GPS satellites broadcast their location and time, trilateration measure distances to pinpoint their exact position on Earth. While triangulation is associated with surveying, no angles are actually involved in GPS positioning. Surveyors usetriangulation to measure distant points – not GPS receivers.

I hope this Question answer might have helped you in understanding Geographical information system and in clearing the Basics interview question of Geographical information system. Let us know if you have any other list of questions answer available in Geographical information system by commenting below in the space provided.

Geoserver FAQs – Geoserver Interview Question

GeoServer is one of the open source GIS Server, which serves Vector and Raster GIS files for instance, Shapefile, GML, KML, NetCDF, GeoTiff, GRIB, HDF5, PostGIS database etc. GeoServer is written in Java, which allows user to process, share, and edit the geospatial data. Here in this post we will check FAQs of Geoserver and Common Question asked during Interview Question.

Geoserver Interview Question – Frequently Asked Question GeoServer

Que. What is GeoServer?
Ans. GeoServer is an open source server for sharing geospatial data.

Que. What are map services?
Ans. Map services are the standard for generating maps on the web, and it is the primary interface to request map products from GeoServer.

Que. What is web server?
Ans. A web server is a program that serves content (web pages, images, files, data, etc.) using HTTP (Hypertext Transfer Protocol). When you use your browser to connect to a website, you contact a web server. The web server takes the request, interprets it, and returns a response, which the browser renders on the screen.

Que. What is web mapping servers?
Ans. A web mapping server is a specialized subset of web server. Like a web server, requests are sent to the server which are interpreted and responded. But the requests and responses are designed specifically toward the transfer of geographic information.

Que. Data sources read by geoserver?
Ans. “Files
Shapefile
GeoTIFF
ArcGrid
JPEG2000
GDAL formats
MrSID
Databases
PostGIS
ArcSDE
Oracle Spatial
DB2
SQL Server” and few more which can be extended by installing extensions.

Que. What you mean by OGC protocols?
Ans. GeoServer implements standard open web protocols established by the Open GeoSpatial Consortium (OGC), a standards organisation. GeoServer is the reference implementation of the OGC Web Feature Service (WFS) and Web Coverage Service (WCS) standards, and contains as well a high performance certified compliant Web Map Service (WMS). It is through these protocols that GeoServer can serve data and maps in an efficient and powerful way.

Que. Name some web mapping servers?
Ans. arcGIS server, geoserver, Mapserver, Mapnik etc.

Que. What is WMS in Geoserver?
Ans. A fundamental component of the web map (and probably the simplest to understand) is the map image. The Web Map Service (WMS) is a standard protocol for serving georeferenced map images generated by a map server. In short, WMS is a way for a client to request map tiles from a server. The client sends a request to a map server, then the map server generates an image based on parameters passed to the server in the request and finally returns an image.

Que. What is WFS in Geoserver?
Ans. A web mapping server can also (when allowed) return the actual geographic data that comprise the map images. One can think of the geographic data as the “source code” of the map. This allows users to create their own maps and applications from the data, convert data between certain formats, and be able to do raw geographic analysis of data. The protocol used to return geographic feature data is called Web Feature Service (WFS).

Que. What is SLD in GeoServer?
Ans. It defines an encoding that extends the WMS standard to allow user-defined symbolisation and coloring of geographic feature and coverage data.

Que. What is OGC?
Ans. The OGC (Open Geospatial Consortium) is an international not for profit organization committed to making quality open standards for the global geospatial community.

Que. Explain OGC filter.
Ans. The OGC Filter Encoding specification provides a generic concept of a filter function. Filters are used to select features or other objects from the context in which they are evaluated. They are similar in functionality to the SQL “WHERE” clause.

Que. Name OGC filter?
Ans. “,”and “.” There are many more, to know visit http://docs.geoserver.org/latest/en/user/filter/filter_reference.html

Que. What is spatial operator?
Ans. Spatial operators are used to specify conditions on the geometric attributes of a feature.

Que. What are the steps to publish data on geoserver?
Ans. Build workspace and add spatial data (Shape file or raster geoTiff) store after that publish the file by providing SRS information.

Que. How can we style data on geoserver?
Ans. To style data in geoserver you can visit style tab in data section.

Que. What is layer preview?
Ans. Layer preview in a section under data heading, which gives the details of published layer.

Que. Name format in which we can see layer in layer preview section.
Ans. KML, shapefile, CSV, geojson, GML etc.

Que. Name some vector data sources available on geoserver store.
Ans. ESRI shape file, postGIS, geoPackage, java property, and web feature server.

Que. Name some raster data sources available on geoserver store.
Ans. ArcGrid, geoTiff, gtopo30, Imagemosaic, worldImage, Netcdf and Grib with extension.

Que. What is caching defaults?
Ans. Caching Defaults page shows the global configuration options for the tile caching functionality in GeoServer

Que. What is geoWebCache?
Ans. Maps are often static. As most mapping clients render WMS (Web Map Service) data every time they are queried, this can result in unnecessary processing and increased wait times. GeoWebCache optimizes this experience by saving (caching) map images, or tiles, as they are requested, in effect acting as a proxy between client (such as OpenLayers or Google Maps) and server (such as GeoServer, or any WMS-compliant server). As new maps and tiles are requested, GeoWebCache intercepts these calls and returns pre-rendered tiles if stored, or calls the server to render new tiles as necessary. Thus, once tiles are stored, the speed of map rendering increases by many times, creating a much improved user experience.

Que. What are the data format which Can be styled on geoserver?
Ans. point, line, polygon and raster

Que. Can we replace point markers by icons?
Ans. yes, we Can. By using styling option and giving icon name in element.

Que. What is worldImage?
Ans. A world file is a plain text file used to georeference raster map images. This file (often with an extension of .jgw or .tfw) accompanies an associated image file (.jpg or .tif). Together, the world file and the corresponding image file is known as a WorldImage in GeoServer.

Que. What id Image Mosiac?
Ans. Imaging mosaicing is being doen in this project such that images taken by normal camera Can be used to create a larger field of view using a image mosaicing program. The program is basically a tools which help you to find out the corresponding camera angles that you used to take the image.

Que. What is arcGrid?
Ans. ESRI ArcInfo Grid (ESRI_grid), also known as ArcGrid, is a raster file format developed by ESRI to contain information about geographic space in a grid.

Que. What is PostGIS?
Ans. PostGIS is a spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects allowing location queries to be run in SQL.

Que. What is Gtopo30?
Ans. GTOPO30 is a global digital elevation model (DEM) with a horizontal grid spacing of 30 arc seconds (approximately 1 kilometer). GTOPO30 was derived from several raster and vector sources of topographic information.

Que. What is tile Layer in geoserver?
Ans. It shows a listing of all of the layers known to the integrated GeoWebCache. It is similar to the Layer Preview for GeoWebCache.

Que. What is SRS in GeoServer?
Ans. A spatial reference system (SRS) or coordinate reference system (CRS) is a coordinate-based local, regional or global system used to locate geographical entities. A spatial reference system defines a specific map projection, as well as transformations between different spatial reference systems.

Que. What is Raster image?
Ans. A raster consists of a matrix of cells (or pixels) organized into rows and columns (or a grid) where each cell contains a value representing information, such as temperature. Rasters are digital aerial photographs, imagery from satellites, digital pictures, or even sCanned maps.

Que. What is vector?
Ans. A representation of the world using points, lines, and polygons. Vector models are useful for storing data that has discrete boundaries, such as country borders, land parcels, and streets.

Que. Why geoserver is used?
Ans. With suitable preparation of data it excels at handling very large datasets, both raster and vector. It produces high quality rendering of maps and Can handle hundreds to thousands of map layers easily.

Que. Can geoserver provide faster acces for vector data.
Ans. yes.

Que. What is web administration interface?
Ans. the Web administration interface is a web-based tool for configuring all aspects of GeoServer, from adding data to changing service settings. In a default GeoServer installation, this interface is accessed via a web browser at http://localhost:8080/geoserver/web.

Que. What is granule?
Ans. In image mosiac, each individual image is commonly referred to as a granule.

Que. What is store in Geoserver?
Ans. A store connects to a data source that contains raster or vector data. A data source Can be a file or group of files, a table in a database, a single raster file, or a directory (for example, a Vector Product Format library). The store construct allows connection parameters to be defined once, rather than for each data-set in a source.

Que. What layer mean in Geoserver?
Ans. In GeoServer, the term “layer” refers to a raster or vector dataset that represents a collection of geographic features. Vector layers are analogous to “featureTypes” and raster layers are analogous to “coverages”.

Que. What is native SRS?
Ans. Specifies the coordinate system the layer is stored in.

Que. Explain layer group in geoserver.
Ans. A layer group is a container in which layers and other layer groups Can be organized in a hierarchical structure. A layer group Can be referred to by a single name in WMS requests. This allows simpler requests, as one layer Can be specified instead of multiple individual layers. A layer group also provides a consistent, fixed ordering of the layers it contains, and Can specify alternate (non-default) styles for layers.

Que. What is GML?
Ans. Geographic Markup Language (GML) is a XML based format for representing vector based spatial data.

Que. Explain geotiff format.
Ans. GeoTIFF is a public domain metadata standard which allows georeferencing information to be embedded within a TIFF file. The potential additional information includes map projection, coordinate systems, ellipsoids, datums, and everything else necessary to establish the exact spatial reference for the file.

Que. Why TFW format is used?
Ans. The TFW file extension is used for plain text files that store X and Y pixel size, rotational information, and world coordinates for a map that is stored as a TIFF image in a GIS application. A GIS (geographic information system) enables you to envision the geographic aspects of a body of data.

I hope this Question answer might have helped you in understanding Geoserver and in clearing the Basics interview question of Geoserver. Let us know if you have any other list of questions answer available in Geoserver by commenting below in the space provided.

Install PostGIS and PostgreSQL in Linux Ubuntu 16.4

In this post we are going to talk about How to install PostGIS and PostgreSQL in ubuntu 16.4 (LTS) or Linux system. As we know geographic information system (GIS) is a system designed to capture, store, manipulate, manage, and present spatial or geographic data. And PostGIS adds support for geographic objects allowing location queries to be run in SQL database. As PostGIS is a spatial database extender for PostgreSQL object-relational database. So without wasting time, Let’s start the post to know How to install PostGIS and PostgreSQL in your system.

Intro to PostGIS and PostgreSQL – Install

What is PostGIS?

PostGIS is an open source software program that adds support for geographic objects to the PostgreSQL object-relational database. PostGIS follows the Simple Features for SQL specification from the Open Geospatial Consortium (OGC).

Technically PostGIS was implemented as a PostgreSQL’s extension. And There are a large number of software products that can use PostGIS as a database backend.

The PostGIS implementation is based on “light-weight” geometries and indexes optimized to reduce disk and memory footprint. Using light-weight geometries helps servers increase the amount of data migrated up from physical disk storage into RAM, improving query performance substantially.

PostGIS is registered as “implements the specified standard” for “Simple Features for SQL” by the OGC. PostGIS has not been certified as compliant by the OGC.

What is PostgreSQL?

PostgreSQL, often simply Postgres, is an object-relational database management system (ORDBMS) with an emphasis on extensibility and standards compliance. As a database server, its primary functions are to store data securely and return that data in response to requests from other software applications. It can handle workloads ranging from small single-machine applications to large Internet-facing applications (or for data warehousing) with many concurrent users; on macOS Server, PostgreSQL is the default database and it is also available for Microsoft Windows and Linux (supplied in most distributions). PostgreSQL is a powerful, open source object-relational database system and It runs on all major operating systems.

It is fully ACID compliant, has full support for foreign keys, joins, views, triggers, and stored procedures (in multiple languages)
PostgreSQL supports compound, unique, partial, and functional indexes which can use any of its B-tree, R-tree, hash, or GiST storage methods. GiST(Generalized Search Tree) serves as a foundation for many public projects that use PostgreSQL such a OpenFTS and PostGIS. And as I described above PostGIS is a project which adds support for geographic objects in PostgreSQL, allowing it to be used as a spatial database for geographic information systems (GIS), much like ESRI’s SDE or Oracle’s Spatial extension.

Install PostGIS and PostgreSQL

Installation of PostGIS and PostgreSQL is much simpler then you think. PostgreSQL is available in all Ubuntu versions by default. However, Ubuntu “snapshots” a specific version of PostgreSQL that is then supported throughout the lifetime of that Ubuntu version. Other versions of PostgreSQL are available through the PostgreSQL apt repository.
The PostgreSQL apt repository supports LTS versions of Ubuntu (14.04 and 16.04) on amd64, i386 and ppc64el architectures as well as select non-LTS versions(17.04). While not fully supported, the packages often work on other non-LTS versions as well, by using the closest LTS version available.
The following describes how to install Postgresql 9.6, PostGIS 2.3, pgRouting 2.3, PGAdmin on Ubuntu version 16.04. It is assumed to also work on Linux Mint, Lubuntu, and Xubuntu.
Run these in terminal:

  • Verifying version of ubuntu
    sudo lsb_release -a
  • Add Repository to sources.list

    For xenial (16.4.2 LTS)

    sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt xenial-pgdg main" >> /etc/apt/sources.list'
  • Adding keys
    wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add - 
    sudo apt-get update
  • Installation

    The following will install postgresql 9.6, PostGIS 2.3, PGAdmin4, pgRouting 2.3 and additional supplied modules including the adminpack extension:

    sudo apt-get install postgresql-9.6
    
    sudo apt-get install postgresql-9.6-postgis-2.3 postgresql-contrib-9.6
    
    postgresql-9.6-postgis-scripts
    
    #to get the commandline tools shp2pgsql, raster2pgsql you need to do this
    sudo apt-get install postgis
  • To get pgRouting
    # Install pgRouting 2.3 package
    sudo apt-get install postgresql-9.6-pgrouting

Now we have successfully installed PostgreSQL and PostGIS into the system and pgAdmin lets you create everything using user interface. You don’t need to remember queries to create tables sequence etc. But I am still showing how to create the database from command line .

You may look over full pgRouting postgresql post in detail.

  • Enable Adminpack

    While in terminal, log in to the psql console as postgres user:

    sudo -u postgres psql
    CREATE EXTENSION adminpack;

    Never install PostGIS in the postgres database, create a user database You can also enable the PostGIS extension here (or with the GUI as described below):

    sudo -u postgres psql
    CREATE DATABASE gisdb;\connect gisdb;
    
    CREATE SCHEMA postgis;
    
    ALTER DATABASE gisdb SET search_path=public, postgis, contrib;
    
    \connect gisdb; 
     -- this is to force new search path to take effect
    
    CREATE EXTENSION postgis SCHEMA postgis;
    
    SELECT postgis_full_version();

    should give you output something like this:

                           postgis_full_version
    -----------------------------------------------------------------------
    POSTGIS="2.4.3 r16312" PGSQL="96" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 1.11.3, released 2015/09/16" LIBXML="2.9.3" LIBJSON="0.11.99" LIBPROTOBUF="1.2.1" RASTER
    (1 row)
  • Install pgRouting – postgis and postgresql

    CREATE  EXTENSION pgrouting;
    SELECT * FROM pgr_version();

    should give you:

    version |  tag   |   hash    | branch | boost
    --------+--------+-----------+--------+--------
      2.5.2 | v2.5.2 | 60585f1f7 | master | 1.58.0
    (1 row)
  • Exit the psql console:
    \q

    This is how we can make database and create schema in command line .

Now let’s see how we can do it in pgAdmin :

PgAdmin – Install PostGIS and PostgreSQL

PostgreSQL has a number of administrative front-ends. The primary one is psql a command-line tool for entering SQL queries. Another popular PostgreSQL front-end is the free and open source graphical to pgAdmin. All queries done in pgAdmin can also be done on the command line with psql.

  • Find pgAdmin and start it up.

    Install PostGIS and PostgreSQL
    Install PostGIS and PostgreSQL
  • If this is the first time you have run pgAdmin, you should have a server entry for PostGIS (localhost:5432) already configured in pgAdmin. Double click the entry, and enter anything you like at the password prompt to connect to the database.
    The PostGIS database has been installed with unrestricted access for local users (users connecting from the same machine as the database is running). That means that it will accept any word you provide. If you need to connect from a remote computer, the password for the PostgreSQL user has been set to PostgreSQL.

Creating a Database

  •  Open the Databases tree item and have a look at the available databases. The PostgreSQL database is the user database for the default PostgreSQL user and is not too interesting to us.
  • Right-click on the Databases item and select New Database.
    Install PostGIS and PostgreSQL
  • Fill in the New Database form as shown below and click OK.
     Name   |  nyc     |
     -------+----------+
     Owner  | postgres |

    Install PostGIS and PostgreSQL
    Install PostGIS and PostgreSQL
  • Select the new nyc database and open it up to display the tree of objects. You’ll see the public schema.
    Install PostGIS and PostgreSQL
  • Click on the SQL query button indicated below (or go to Tools > Query Tool).Install PostGIS and PostgreSQL
  • Enter the following query into the query text field to load the PostGIS spatial extension:
    CREATE EXTENSION postgis;
  • Click the Play button in the toolbar (or press F5) to “Execute the query.”
  • Now confirm that PostGIS is installed by running a PostGIS function:
    SELECT postgis_full_version();

You have successfully created a PostgreSQL database with PostGIS!! Let us know by commenting below if you have faced any problem in Install PostGIS and PostgreSQL. Or comment below with the trick you have applied to install postgis.

PGrouting PostGIS Postgresql – No need for Google routing

Do you have all road data with you and want to creating routing from that according to your algorithm? Needs an alternative to Google Map API, when having your own road datasets? PGrouting with PostGresSql can help you out by doing that. Here in this post we will look for PGRouting PostGreSql implementation steps by steps and finding the direction with PGRouting. Connection between PostGres and QGIS and query data and see the result in QGIS Desktop.

Prerequisite for PGrouting PostGIS Postgresql:

  • Installed QGIS and installed PostGreSql
  • Basic Knowledge of PostGreSQL
  • Basic knowledge with QGIS Desktop
  • Road Map Shapefile

Here we will consider Road Map Shapefile, on which we will query and get the routing. In this article we will see how we can query the road network shapefile to find out the shortest path. The results can be seen in QGIS Desktop software. Here postGIS is used to generate road network. In this tutorial we have id of each route, which is used to query the shortest route. You will understand more easily once you read this article throughly. Here PGrouting has used to find out the shortest path.

Install Postgresql PostGIS PGRouting:

Its installation is simple process include few steps (written an article for linux based system). Here are few points for installing postgresql PGRouting:

# Create the file /etc/apt/sources.list.d/pgdg.list, and add a line for the repository

--> sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ CODENAME-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

The codename can find by using given command

 --> lsb_release -cs

Output:

 Codename xanial

Then replace this codename in command.

# Import the repository key, update the package lists

--> sudo apt-get install wget ca-certificates
 --> wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
 --> sudo apt-get update

# Install PGrouting based on your postgresql Installation:

--> sudo apt-get install postgresql-9.6-pgrouting

To be up to date with changes and improvements follow the given command

--> sudo apt-get update & sudo apt-get upgrade

PGRouting PostGreSql PostGIS Shortest Path Steps:

In this article we are using postgres 9.6, PostGIS 2.4.2 and Pgrouting 2.5.2. It is better to check versions for all required software as query syntax change with version. Firstly create a database.

1. Create database in PostGreSql for PGRouting:

You can create a database in Ubuntu terminal. For that you need to follow the given command-

 --> sudo -u postgres createdb -O DATABASE_USER DATABASE_NAME

where -U username, Createdb is command which create new postgresql database, -O output file name, last two options are Database user-name and name for database. For more option in psql visit https://www.postgresql.org/docs/9.0/static/app-psql.html link.

2. Add shape file in postgresql pgrouting database:

If you are using pgAdmin3 then you can open the database by providing user name and password.

In Database you can add shapefile by clicking option PostGIS shape file and DBF loader. Here first off define the user-name with proper password and database name. Then add shape file and import it.

You can use this link to import or upload Shapefile in PostGreSql database.

Now refresh the database and expand public-> tables option you see the shape file’s attribute table.

3. Add Source and target column in attribute table:

The given command will add column in attribute table, named as source and target with integer data type. Here roads_table is the attribute table or imported shape file.

--> ALTER TABLE roads_table ADD COLUMN "source" integer;
--> ALTER TABLE roads_table ADD COLUMN "target" integer;

4. Create topology – PGRouting:

Here you must be aware of what is topology when working with spatial system. Topology is a set of rules and behaviours that model how points, lines, and polygons share coincident geometry.

Here creating topology means attaching nodes to every end point of route. This is done using method from pgrouting that is pgr_createTopology().
This takes table name, tolerance, geom field name and id as inputs.

--> SELECT pgr_createTopology('roads_table', 0.001, 'the_geom', 'id')

More detailed explanation is given below:

The topology creation function accepts the following parameters:

-> edge_table:

Text Network table name. (may contain the schema name AS well)

-> tolerance:

Float8 Snapping tolerance of disconnected edges. (in projection unit)

-> the_geom:

Text Geometry column name of the network table. Default value is the_geom.

-> Id:

Text Primary key column name of the network table. Default value is id.

-> Source:

Text Source column name of the network table. Default value is source.

-> Target:

Text Target column name of the network table. Default value is target.

-> rows_where:

Text Condition to SELECT a subset or rows. Default value is true to indicate all rows that where source or target have a null value, otherwise the condition is used.

-> Clean:

Boolean Clean any previous topology. Default value is false.

For more details: http://docs.pgrouting.org/2.2/en/src/topology/doc/pgr_createTopology.html

5. Create network table – PGrouting PostGIS Postgresql:

This table contains all information such as gid, length of routes, name of roads, source and target. Here source and target is taken from node table where as other information from attribute table. For this first we need to create node table.

In node table you have source as a start_id and target as end_id.

CREATE TABLE node AS
 SELECT row_number() OVER (ORDER BY foo.p)::integer AS id,
 foo.p AS the_geom
 FROM (
 SELECT DISTINCT roads_table.source AS p FROM roads_table
 UNION
 SELECT DISTINCT roads_table.target AS p FROM roads_table
 ) foo
 GROUP BY foo.p;

This explains that distinct values of source and target from roads_table table is selected and union operation has performed. Then number of rows are selected from this union table and saved them in node table.

CREATE TABLE network AS
 SELECT a.*, b.id as start_id, c.id as end_id
 FROM roads_table AS a
 JOIN node AS b ON a.source = b.the_geom
 JOIN node AS c ON a.target = c.the_geom;

This query explains that in network table b.id is named as start_id and c.id as end_id.

Now we will use pgr_dijkstra method from PGrouting PostGIS Postgresql

The minimal syntax is given

pgr_dijkstra(TEXT edges_sql, BIGINT start_vid, BIGINT end_vid)
 RETURNS SET OF (seq, path_seq, node, edge, cost, agg_cost) or EMPTY SET

This returns seq, path sequence, node, edge, cost, agg_cost fields.

Select seq, node, edge,cost, geom from pgr_dijkstra(
 'Select gid as id, source, target, st_length(geom) as cost from network', 3566,20051, false) as di
 JOIN network pt
 ON di.edge = pt.gid ;

Here we have joined network table to select geometry field. This all command would be running in SQL window in DB manager option in QGIS.

You can create a shape file as a result for query. For that you need to click on load as new layer option then provide geom as geometry option and edge as column with unique values and click load. The result layer will be added to canvas of QGIS.

PgRouting PostGIS PostGreSql using Latitude Longitude for source and destination:

You just need to change the last command in SQL window of QGIS software.

Select seq, node, edge,cost, geom, agg_cost from pgr_dijkstra(
 'Select gid as id, source, target, st_length(geom::geography)/1000 as cost from network',(SELECT source FROM network
 ORDER BY geom <-> ST_SetSRID(ST_Point
 (74.862413,24.476381),4326) LIMIT 1),
 (SELECT source FROM network
 ORDER BY geom <-> ST_SetSRID(ST_Point
 (75.857734,22.719588),4326) limit 1), false) as di
 JOIN network pt
 ON (di.edge = pt.gid);

This query explains that we are using pgr_dijkstra from pgrouting which takes sql_text,integer start_id, integer end_id and boolean type for directed route. If route is directed, give input as true otherwise false. Here in this article we have undirected route. As now in place of we want to give latitude and longitude so for that given query has executed.

SELECT source FROM network ORDER BY geom <-> ST_SetSRID(ST_Point (75.857734,22.719588),4326) limit 1

This part is little interesting, first of all we need to understand that always we provide latitude longitude of point(place), not of any line (road). So this point can be restaurant, stops, hotels or hospitals etc.

Now the very first task is to find out the nearest path from these points. For that we used <-> from postgis.

<-> — Returns the distance between two points.

Now we may have 2 or more path from selected point. So the shortest one should be selected from these path, For that we used order by command which arranges these path in ascending order and after that limit 1 command selects top most 1 row, which his nothing but the shortest path from source to path. Similar concept is applied on end point also.

Syntax of postgresql:

double precision <->( geometry A , geometry B );

The <-> operator returns the 2D distance between two geometries. Used in the “ORDER BY” clause provides index-assisted nearest-neighbor result sets. For PostgreSQL below 9.5 only gives centroid distance of bounding boxes and for PostgreSQL 9.5+, does true KNN (K nearest neighbor) distance search giving true distance between geometries, and distance sphere for geographies.

Syntax of postgresql:

geometry ST_SetSRID(geometry geom, integer srid); 
geometry ST_Point(float x_lon, float y_lat);

In ST_Point we give source and destination latitude longitude. Using ST_SetSRID Set the SRID on a geometry to a particular integer value. Here EPSG 4326 is used which is WGS84 datum. EPSG stands for European Petroleum Survey Group, They publish a database of coordinate system information. SELECT source FROM network this returns source id. Similarly got source id of end point. Then cost is set as length of route in kilometers. All these provided to pgr_dijsktra method and join network table to take geometry as output to show result in QGIS.

Output of PGrouting PostGIS Postgresql – No need for Google routing

Here is the output of route which is rendered with QGIS Desktop, where green color indicates the road network and red color display the shortest distance we get from A and B.

PGrouting PostGIS Postgresql - No need for Google routing
PGrouting PostGIS Postgresql – No need for Google routing

We got good results as distance from A to B is calculated as 368Km and on Google map it is 361 km. Similarly many points have tested and result vary from 6 to 8Km.

Did you tried PGRouting postgis postgresql? If you are facing any issue, do let us know by commenting below with the solution.

KML to GML – Convert Keyhole to Geography

Sometimes we need to convert KML to GML where the software supports GML language. But before converting Keyhole markup language to Geography markup language, you should know the basic structure of KML and GML. So that if the file is corrupted then before converting it you can correct it manually and process the same in any GIS converter software to work properly. If you already know structure of this files, then you can directly navigate to the main topic i.e kml to gml conversion of this page.

Here is the Online Converter Tool from KML To GML 

Know KML and GML data structure before converting kml to gml

WHAT IS KML (Keyhole Markup Language)? – KML (Keyhole Markup Language), is an XML grammar and file format for modeling and storing geographic features such as points, lines,images, and polygons for display in the Google Earth client.KML is based on GML, although it doesn’t formally import GML schemas. KML language is used by a variety of GIS and mapping applications and the specifications are freely available to the public and available to the user community without charge or restriction. The Google Earth client supports a number of display features for rich presentation of GIS data. All of the features supported by the Google Earth client are described in KML. The Google Earth client supports a number of two-dimensional geometric shapes for display in the 3D viewer.

<Schema name="roads" id="roads">
 <SimpleField name="MED_DESCRI" type="string"></SimpleField>
 <SimpleField name="RTT_DESCRI" type="string"></SimpleField>
 <SimpleField name="F_CODE_DES" type="string"></SimpleField>
 <SimpleField name="ISO" type="string"></SimpleField>
 <SimpleField name="ISOCOUNTRY" type="string"></SimpleField>
 <SimpleField name="Length_km" type="float"></SimpleField>
 <SimpleField name="Latitude" type="string"></SimpleField>
 </Schema>
 <Folder><name>roads</name>
 <Placemark>
 <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
 <ExtendedData><SchemaData schemaUrl="#roads">
 <SimpleData name="MED_DESCRI">Without Median</SimpleData>
 <SimpleData name="RTT_DESCRI">Secondary Route</SimpleData>
 <SimpleData name="F_CODE_DES">Road</SimpleData>
 <SimpleData name="ISO">IND</SimpleData>
 <SimpleData name="ISOCOUNTRY">US</SimpleData>
 <SimpleData name="Length_km">0.3</SimpleData>
 </SchemaData></ExtendedData>
 <LineString><coordinates>77.8277403975188,35.5012774951028 77.8257523065223,35.4995003281062</coordinates></LineString>
 </Placemark>

WHAT IS GML (Geography Markup Language)? GML (Geography Markup Language) is only concerned with the representation of the geographic data content. While GML is an effective means for transporting geographic information from one place to another we expect that it will also become an important means of storing geographic information as well.

<gml:boundedBy>
 <gml:Box>
 <gml:coord><gml:X>-164404.6900820375</gml:X><gml:Y>893749.1179630321</gml:Y></gml:coord>
 <gml:coord><gml:X>2727970.187011702</gml:X><gml:Y>3932312.865004988</gml:Y></gml:coord>
 </gml:Box>
 </gml:boundedBy>
 <gml:featureMember>
 <ogr:raods fid="raods.0">
 <ogr:geometryProperty><gml:LineString srsName="EPSG:32643"><gml:coordinates>756486.657418272,3932312.4133327 756311.93383727,3932110.06520674</gml:coordinates></gml:LineString></ogr:geometryProperty>
 <ogr:MED_DESCRI>Without Median</ogr:MED_DESCRI>
 <ogr:RTT_DESCRI>Secondary Route</ogr:RTT_DESCRI>
 <ogr:F_CODE_DES>Road</ogr:F_CODE_DES>
 <ogr:ISO>IND</ogr:ISO>
 <ogr:ISOCOUNTRY>US</ogr:ISOCOUNTRY>
 <ogr:Length_km>0.3</ogr:Length_km>
 <ogr:Latitude xsi:nil="true"/>
 </ogr:USraods>
 </gml:featureMember>
 <gml:featureMember>

Convert KML to GML using Ogr2ogr utility-

For using this utility you need to install GDAL OGR2OGR in your system. To  install this you can follow the given commands.

KML to GML - Convert Keyhole to Geography
KML to GML – Convert Keyhole to Geography

If you have already install ogr2ogr utility you can check by typing ogr2ogr in terminal.

KML to GML - Convert Keyhole to Geography

Now run the given command to convert from KML to GML-

--- ogr2ogr -f 'GML' Output_GML.gml Input_KML.kml

Changing Coordinate System of Output File kml to gml-

Sometimes we need different coordinate system. So to get different coordinate system from input you can follow this given command.

--- ogr2ogr -f 'GML' -t_srs EPSG:32643 -s_srs EPSG:4326 Output_GML.gml Input_KML.kml

Convert KML (KeyHole Markup Language) to GML (Geography Markup Language) Using PHP Code-

If you want the conversion using programing or don’t want to use terminal then this can also be done using PHP. You can create a function that defined this command as string and can give this string in shell_exec() method to execute. Shell_exec() actually execute the command and returns output as string.

public function kmltogml($kmlfilepath,$output,$srsno,$srsold){
 $query="ogr2ogr -f GML -t_srs EPSG:$srsno -s_srs EPSG:$srsold $output.gml $kmlfilepath";
 shell_exec($query);
 }

Generated output of kml to gml –

KML to GML - Convert Keyhole to Geography
KML to GML – Convert Keyhole to Geography

If you have any problem regrading this tutorial, please let us know via comments  in provided comments box.

Embed HTML Google Map

It is not a whole HTML file or long scripts. It is just one HTML tags i.e  <iframe>,  to show map. On your computer, you can embed a map, Street View image, driving directions, or search of map into your website or blog. On your computer, phone, or tablet, you can share a location or map with others over email, Google+, Facebook, Twitter, or text. Lets see how to Embed HTML Google Map in your website.

There are three main part in iframe tag of google map which help us to set proper map.
1. Mode
2. API_key
3. parameter

Example of html iframe tag to embed html google map:

googlemaps : https://www.google.com/maps/embed/v1/MODE?key=YOUR_API_KEY &PARAMETER&w=600&h=450

Mode in google map link-

The mode section mainly consist place, directions, search, view, or streetview.

  • Place in google map link- Place displays a map of particular place or address, such as a landmark, famous building, geographic feature, or town.
  • Directions in google map link- mode displays the path between two or more specified points on the map, as well as the distance and travel time. Search- mode displays results for a search across the visible map region.
  • View- (streetview) mode returns a map with no markers or directions.

API_Key in Google Map to Embed html:

This is your free API key. You need to login to your mail account and navigate to

https://developers.google.com/maps/documentation/embed/get-api-key

link to get this API key.

Parameter in Google Map to embed html:

This includes some optional parameter which can be mode specified also.
The parameters are given as Center- To set this parameter you need to give comma separated latitude longitude value. This will set the map view in middle.

  • Zoom- To set Zoom level You need to give integer value from 0 to 21, where 0 defines the whole world view and 21 defines the building level zoomed view. This also depends on location selected and data availability of that location.
  • Map Type- there are two type of map roadmap or satellite. Region- defines the appropriate borders and labels to display, based on geo-political sensitivities.
  • Language- This set the language, which will be display on map tiles for User interface elements and labels available on map.

Other than these option we also have some option to set width and height of google map for html embed. We can also set frame border and style of that border. We can specify the allow full screen option to make map available on full window.

Steps to Embed HTML Google Map

Step 1:

Navigate yourself to https://www.google.com/maps link.

Embed HTML Google Map

Step 2:

Sign in with Google account.

Step 3 to embed google map html:

click option menu and navigate to Your places-> maps-> create a map in bottom. A new window will open in new tab.

Embed HTML Google Map
Embed HTML Google Map

Step 4 to Embed HTML Google Map:

Now Click on Untitled Map, Write a title and description then hit to save.

Embed HTML Google Map

Step 5:

You have two ways to add markers on map.

1. You can directly choose marker option and place them on map, wherever you need.

Embed HTML Google Map

2. You can specify the location by providing location or address. After adding markers on map you must save the locations.

Embed HTML Google Map

Step 6 to Embed HTML Google Map:

Now click to share option and set the privacy setting to “public on web” or you can choose people who can view and access the map. Then save the details and click to done.

Embed HTML Google Map

Step 7:

Then Click to option menu on title window and hit to embed on my site. This will provide you a link containing <iframe> tag. You can use this link any where you want.

Embed HTML Google Map
Embed HTML Google Map

You can use this iframe link in your web site to show your business location on map. Hope you enjoyed this tutorial.

There is much more for you as Embed Google map with 2 or more Markers for Web pages or any conversion as- shape file to KML and shapefile to GML etc.

If you face problem during implementation of this tutorial, please let us know via comments.

Publish Style Vector Dataset on GeoServer

GoeServer is one of the best server for storing Vector data. Geoserver is open source software and free to use. To know how to publish vector data and style it on Geoserver you can follow this tutorial. Before this you need to install Geoserver on your system for that read out our previous tutorial, install first GeoServer on Windows or Ubuntu operating system. You can also look for publish and style raster dataset in GeoServer.

GeoServer supports various Vector DataSet:

  • Shapefile
  • Directory of spatial files
  • Java Properties
  • GeoPackage
  • GML

Here we will use Shapefile as vector dataset as an example to publish and style in map in geoserver.

A shapefile stores non-topological geometry and attribute information for the spatial features in a data set. The geometry for a feature is stored as a shape comprising a set of vector coordinates whereas attribute information can be seen in the attribute table.

GeoServer has been optimized for serving large shapefile (GB size) with good speed. We need to publish shapefile and then using WMS service we can use data with high speed. The OGC Web Map Service (WMS) specification defines an HTTP interface for requesting georeferenced map images from a server.

How a shapefile can be published on geoserver is described below. The published and styled data will look something like image showed as feauregiven in the post . This geometry for shapefile is point and icon based styling has used.

Publish Style Vector Dataset on GeoServer

Publish Vector Data on GeoServer  – Host Shapefile SHP

We can publish many type of files on geoserver that can be in raster or vector format. In this tutorial we will see how we can publish shape file on GeoServer.

Start GeoServer application in your computer. It will run in command prompt then in web browser search localhost:8080/geoserver/web. Provide the Username and Password and click login to login as administrator of GeoServer.

Step 1 to publish vector data in geoserver:

First of all you need to login to GeoServer then create a workspace, which can be done by selecting workspace option on the right side of screen under data section. Add the new workspace give a name and URI. In information technology, a Uniform Resource Identifier (URI) is a string of characters used to identify a resource, which can be same as name and submit the information.

Publish Style Vector Dataset on GeoServer

Step 2:

Now add the store by selecting stores option under same section. Click Add new store and select shapefile or directory of spatial files. Under directory of spatial file add your work space and data source name. Under connection parameters browse your file location then click save option. After saving you will be able to publish the layer. Click publish option.

Publish Style Vector Dataset on GeoServer

Step 3 to publish vector data in geoserver:

after selecting publish option check the name of shape file. Under Coordinate Reference Systems heading check the coordinate system of your shape file. Under bounding boxes select Computes from SRS (spatial reference system) bound and in the next part select compute from native bound. Then save the information. After saving you will be able to see the shapefile name with your workspace and store name.

Publish Style Vector Dataset on GeoServer
Publish Style Vector Dataset on GeoServer

Step 4:

Now select the Layer Preview option under same section. And open your shape file using openLayer option in Command format column.

Publish Style Vector Dataset on GeoServer

As the layer is visible now you have a link in URL bar. You can add this link in QGIS using add WMS/WMTS layer and see the shape file.
Open QGIS and click the add WMS/WMTS layer option and then click new button to add new WMS layer.

Publish Style Vector Dataset on GeoServer
Publish Style Vector Dataset on GeoServer

Add the URL and click ok.

Publish Style Vector Dataset on GeoServer

Then connect the layer and add to display.

Shape file can contain point, line or polygon, which can be styled on geoServer. To style any feature on geoserver we required to add style name. This style can be customised. Some styling is already given in style option under Data section.

To add built in style to your shapefile follow the given steps-

Step 1:

First of all make sure your file has been added on server. Then open that layer using layer option in data section.

Step 2:

There will be 4 tabs as data, publishing, dimensions and tile caching. As on adding layer you already have visited data tab and set SRS coordinates. Now click publishing tab.

Publish Style Vector Dataset on GeoServer

In publishing tab find the WMS setting option, under that option check the Queryable checkbox and select style in default style dropdown.
There are styles for point, line, polygon and raster.
1. Burg: point
2. Dem: raster
3. Capitals: points
4. Roads: line
5. Lakes: polygon
6. Raster: raster
7. Point: point
8. Line: line
9. Polygon: polygon
10. Rain: raster
11. Population: raster
According to your shape file you can add the style and click to save.

Step 3 of style vector dataset in geoserver:

Now to check the styling click the layer preview option under same data section. Open as openLayer.

For more details you can visit http://docs.geoserver.org/latest/en/user/data/webadmin/layers.html website.

Styling Based on Attributes: Sometimes we need to style according to attributes. For example population greater than 5000, population equal to 5000 and population less than 5000 so we need some coding to define all these.

The Styled Layer Descriptor (SLD) Profile of the Web Map Service (WMS) Encoding Standard defines an encoding that extends the WMS standard to allow user-defined symbolization and colouring of geographic feature (vector data) and coverage data (raster data).

SLD (Styled Layer Descriptor ) has some elements in geoserver for vector dataset as :

The root element for an SLD is <StyledLayerDescriptor>. It contains a Layers and Styles elements which describe how a map is to be composed and styled.

  • <NamedLayer>: A reference to a named layer in the server catalogue
  • <UserLayer>: A layer defined in the style itself
  • <FeatureTypeStyle>: The FeatureTypeStyle element specifies the styling that is applied to a single feature type of a layer. It contains a list of rules which determine the symbology to be applied to each feature of a layer.
  • Under Rule element we specified filter with binary comparison operators PropertyIsEqualTo. Where property name is the attribute column you want to perform operation on and literal is the attribute value.
    <ogc:Filter>
    <ogc:PropertyIsEqualTo>
    <ogc:PropertyName>type</ogc:PropertyName>
    <ogc:Literal>balloonport</ogc:Literal>

In this article we have used Airport shape file, containing attributes as name and type of airports as point feature. So here we have styled this data based on type of airport.

  • PointSymbolizer: which styles features as points
  • LineSymbolizer: which styles features as lines
  • PolygonSymbolizer: which styles features as polygons
  • TextSymbolizer: which styles text labels for features
  • RasterSymbolizer: which styles raster coverages

<PointSymbolizer> in geoserver for vector dataset:

contains an optional <Geometry> element, and a required <Graphic> element specifying the point symbology. So as we want to change the point with icons so graphic element is used. <ExternalGraphic> element specifies an external image file to use as the symbol. Then using onlineResource define the path of graphic and format. The xlink:href attribute specifies the location of the image file. The value can be either a URL or a local pathname relative to the SLD directory. The value can contain CQL expressions delimited by ${ }. The attribute xlink:type=”simple” is also required. The graphic size can be by using size element. Then close all the elements by using “/”.

<PointSymbolizer>
 <Graphic>
 <ExternalGraphic>
 <OnlineResource xlink:type="simple" xlink:href="http://localhost:7080/akshay_ep/ep/05airports/airports/airballoon.png"/>
 <Format>image/png</Format>

Full length code

<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd">
 <NamedLayer>
 <Name>Attribute-based point</Name>
 <UserStyle>
 <Title>GeoServer SLD Cook Book: Attribute-based point</Title>
 <FeatureTypeStyle>
 <Rule>
 <Name>balloonport</Name>
 <Title>balloonport</Title>
 <ogc:Filter>
 <ogc:PropertyIsEqualTo>
 <ogc:PropertyName>type</ogc:PropertyName>
 <ogc:Literal>balloonport</ogc:Literal>
 </ogc:PropertyIsEqualTo>
 </ogc:Filter>
 <PointSymbolizer>
 <Graphic>
 <ExternalGraphic>
 <OnlineResource xlink:type="simple" xlink:href="http://localhost:7080/akshay_ep/ep/05airports/airports/airballoon.png"/>
 <Format>image/png</Format>
 </ExternalGraphic>
 <Size>32</Size>
 </Graphic>
 </PointSymbolizer>
 </Rule>
 </FeatureTypeStyle>
 </UserStyle>
 </NamedLayer>
 </StyledLayerDescriptor>

To apply this code open the style option, add a new style and give name and workspace. After that select SLD ( Styled Layer Descriptor ) from format drop down and copy this code in editor. Validate apply and submit this.
After this open your shape file and repeat the steps described above. In the last open this layer as Openlayer from layer preview section.

Publish Style Raster Dataset On GeoServer

Publish Style Raster Dataset On GeoServer. Do you have raster data and want to host the data on geoserver and create a proper map with styling according to dataset? Well GeoServer gives you a direct and simple method to create a styled map. Before implementing steps to publish and sytle raster dataset on geoserver you need to install first GeoServer on Windows, mac or Ubuntu Pc or Server. If you are looking for publish and style vector dataset on geoserver, you can check this link.

Raster Dataset GeoServer coverage:

Coverage/raster data that geoserver can access are,

1. GeoTIFF (Tagged Image File Format with Geographic information)
2. GTOPO30
3. WorldImage
4. ImageMosaic
5. GeoPackage

In this article we will discuss how we can publish GeoTIFF (.tiff/.tfw format) data on server. The data for this article has been downloaded from the links provided in this article. The raster data contains 3 bands (red, blue, green) information. Here we will use GeoTiff data to demonstrating raster dataset to publish and style in GeoServer.

To publish Raster Dataset data – Steps –  Publish Style Raster Dataset

Here we will first publish the geotiff raster dataset in geoserver as an example:

Step 1:

First of all you need to login to GeoServer then create a workspace, which can be done by selecting workspace option on the right side of screen under data section. Add the new workspace give a name and URI. In information technology, a Uniform Resource Identifier (URI) is a string of characters used to identify a resource, which can be same as name and submit the information.

Publish Style Raster Dataset On GeoServer

Step 2 of Publish Raster Dataset on GeoServer:

Now add the store by selecting stores option under same section. Click Add new store and select GeoTIFF option in Raster Data Sources list.

Publish and Style Raster Dataset On GeoServer
Publish and Style Raster Dataset On GeoServer

Under this option add the workspace, you created and give data source name. Provide the description about your data. Now browse the GeoTIFF file to add and publish this data.

Step 3:

Check the Coordinate Reference Systems and the Bounding Boxes fields are properly set and click on Save.

Step 4 of publish raster dataset on geoserver:

Now you can see the layer and get the WMS link. For this go to Layer Preview option in data section and open the published data as OpenLayer option.

To Style Raster Dataset on GeoServer  Steps –  Publish Style Raster Dataset

To add built in style to your GeoTIFF file follow the given steps.

Step 1:

First of all make sure your file has been added on server. Then open that layer using layer option in data section.

Step 2 to style raster dataset in geoserver:

There will be 4 tabs as data, publishing, dimensions and tile caching. As on adding layer you already have visited data tab and set SRS coordinates. Now click publishing tab.

Publish and Style Raster Dataset On GeoServer
Publish and Style Raster Dataset On GeoServer

In publishing tab find the WMS setting option, under that option check the Queryable check box and select style in default style drop down.

There are styles for point, line, polygon and raster in Geoserver:

1. Burg: point
2. Dem: raster
3. Capitals: points
4. Roads: line
5. Lakes: polygon
6. Raster: raster
7. Point: point
8. Line: line
9. Polygon: polygon
10. Rain: raster
11. Population: raster

According to your shape file you can add the style and click to save.

Step 3:

Now to check the styling, add Raster option as style and click the layer preview option under same data section. Open as openLayer.

You can add your own SLD (Styled Layer Descriptor) profile to style the GeoTiff data. For this you can follow this article and for more information you can visit http://docs.geoserver.org/latest/en/user/styling/sld/reference/rastersymbolizer.html link.

The Styled Layer Descriptor (SLD) supported in geoserver raster dataset:  

Profile of the Web Map Service (WMS) Encoding Standard defines an encoding that extends the WMS standard to allow user-defined symbolisation and colouring of geographic feature (vector data) and coverage data (raster data).

SLD has some elements as:

  • <StyledLayerDescriptor> Which is the root element for an SLD. It contains a Layers and Styles elements which describe how a map is to be composed and styled.
    <NamedLayer>: A reference to a named layer in the server catalogue
  • <UserLayer>: A layer defined in the style itself
  • <FeatureTypeStyle>: The FeatureTypeStyle element specifies the styling that is applied to a single feature type of a layer. It contains a list of rules which determine the symbology to be applied to each feature of a layer.
    <Rule>: Styling rules define the portrayal of features. A rule combines a filter with any number of symbolizers. Features for which the filter condition evaluates as true are rendered using the symbolizers in the rule.
  • <RasterSymbolizer>: styles raster coverages.
    The <Opacity> element sets the transparency level for the entire rendered image. As is standard, the values range from zero (0) to one (1), with zero being transparent, and one being opaque.
  • The <ChannelSelection> element specifies how dataset bands are mapped to image colour channels. Named dataset bands may be mapped to red, green and blue channels, or a single named band may be mapped to a grayscale channel.
  • Here we can select any of the band or all three band. But particularly in this article we have selected a single band of an RGB image as a grayscale channel and re-colorizing it via a ColorMap.
  • A color map is defined by a sequence of <ColorMapEntry> elements. Each <ColorMapEntry> element specifies a color and a quantity attribute. The quantity refers to the value of a raster pixel. The color value is denoted in standard hexadecimal RGB format (#RRGGBB). <ColorMapEntry> elements can also have opacity and label attributes. As in the code quantity is given as 0, 150, 200 and 255. Then the pixels having other values get interpolated range of color.
  • In the last close all the elements and save the style.
    After that open the layer option and select the geotiff file. Add the style in publishing tab and save the layer. To view this style over layer, open layer preview option and open this layer as Openlayer option.

Full length code Publish Style Raster Dataset On GeoServer

<?xml version=”1.0″ encoding=”UTF-8″?>
<StyledLayerDescriptor version=”1.0.0″
xsi:schemaLocation=”http://www.opengis.net/sld StyledLayerDescriptor.xsd”
xmlns=”http://www.opengis.net/sld”
xmlns:ogc=”http://www.opengis.net/ogc”
xmlns:xlink=”http://www.w3.org/1999/xlink”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
<NamedLayer>
<Name>default_raster</Name>
<UserStyle>
<Title>Default Raster</Title>
<FeatureTypeStyle>
<Rule>
<Name>rule1</Name>
<Title>Opaque Raster</Title>
<Abstract>A raster with 100% opacity</Abstract>
<RasterSymbolizer>
<Opacity>1.0</Opacity>
<ChannelSelection>
<GrayChannel>
<SourceChannelName>1</SourceChannelName>
</GrayChannel>
</ChannelSelection>
<ColorMap extended=”true”>
<ColorMapEntry color=”#0000ff” quantity=”0″/>
<ColorMapEntry color=”#009933″ quantity=”150″/>
<ColorMapEntry color=”#ff9900″ quantity=”200″ />
<ColorMapEntry color=”#ff0000″ quantity=”255″/>
</ColorMap>
</RasterSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

Publish and Style Raster Dataset On GeoServer
Publish Style Raster Dataset On GeoServerHope

Hope this article to Publish Style Raster Dataset On GeoServer is helpful for you and you might be easily able to create a beautiful colour map with the help of geoserver. If you find any problem in following the steps to style and publish the raster layer of geoserver do comment below with the problem in the box provided below.