2

I am trying to display the GIS data on the Google map using PostgreSQL.

I have few Shapefiles, I imported those shapefile into PostgreSQL. Now I am trying to get this data using this query. After running the query I am getting such type of GeoJson form PostgreSQL I found that the data retrieved from Postgresql is not proper format as Google map accepted. The data is in another format please see my GeoJSON data:

$query="SELECT ST_AsGeoJSON(ST_Transform(geom, 4326)) AS geom_in_degrees FROM pymble_10 ";

$result = pg_query($db,  $query);

  $finalArray = array();
  $i=0;

while($row=pg_fetch_row($result)){

   print_r($row);
 }

And i am getting output like this :

Array ( [0] =>
{"type":"MultiPolygon","coordinates":[[[[16826527.7094727,-3992350.20318604],[16826530.7548828,-3992351.11029053],[16826532.8928833,-3992352.14691162],[16826534.1887207,-3992353.50750732],[16826535.0958862,-3992355.12738037],[16826535.7437134,-3992356.68231201],[16826535.8084717,-3992357.97821045],[16826535.6140747,-3992359.27398682],[16826534.9663086,-3992360.50512695],[16826534.059082,-3992361.47698975],[16826532.9577026,-3992362.3192749],[16826531.6619263,-3992362.83758545],[16826530.4309082,-3992362.96722412],[16826528.4871216,-3992363.355896],[16826527.2561035,-3992363.6151123],[16826524.145874,-3992364.32788086],[16826521.9431152,-3992365.04058838],[16826520.4528809,-3992365.23492432],[16826518.6386719,-3992364.97570801],[16826517.3428955,-3992363.6151123],[16826516.1118774,-3992361.2177124],[16826516.046875,-3992358.95001221],[16826516.3060913,-3992357.07110596],[16826517.1484985,-3992355.58081055],[16826518.8331299,-3992353.5723877],[16826520.2584839,-3992352.01739502],[16826521.3599243,-3992350.65667725],[16826522.3319092,-3992350.00878906],[16826524.0812988,-3992349.87921143],[16826527.7094727,-3992350.20318604]]]]} )
  • What output are you expecting? Usually, something like print_r is only used for debugging. You need to use json_encode instead. Additionally, check your geometries; The coordinates seem outside the normal domain of lat-long – Devdatta Tengshe Feb 10 '16 at 8:30
  • yes your point is valid but my output for latlong is 16826527.7094727,-3992350.20318604 but it is not correct format i want google acceptable lat-long. – rupendra bhadoriya Feb 10 '16 at 8:49
  • Without knowing your JavaScript code, it's not possible to figure out what is wrong. Please post more details on how you are using the results of this service in your JS code – Devdatta Tengshe Feb 10 '16 at 10:53
0

ST_AsGeoJSON gives you the geometry in GeoJSON format. Google Maps is probably expecting a feature, or a featurecollection.

It should be clear just watching the geojson.org homepage, where you can find a "feature" GeoJSON example.

You can also compare your GeoJSON with the one found in google map's examples https://storage.googleapis.com/maps-devrel/google.json

Regarding the projection problem, if your geom column is already 4326, you don't need to call the transform function. So your query will be SELECT ST_AsGeoJSON(geom) AS geom_in_degrees FROM pymble_10

However, if projections are correctly set, this should not be a problem.

You can check the column projection with select srid from geometry_columns where f_table_name = 'pymble_10'

and you can check the geometry projection with select st_asewkt(geom) from pymble_10

  • Ok. But in my case i am getting different data format of lat-long. please check the output of my query – rupendra bhadoriya Feb 10 '16 at 8:41
  • Sorry, didn't notice that. What is the srid of the table/data? – fradal83 Feb 10 '16 at 8:54
  • i am using srid 4326 – rupendra bhadoriya Feb 10 '16 at 9:24
  • I've updated my answer – fradal83 Feb 10 '16 at 9:32
  • i tried and it is showing the same srid 4326 – rupendra bhadoriya Feb 10 '16 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.