Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8105549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:11:37+00:00 2026-06-06T00:11:37+00:00

I have a shape file, and I want to show it on the web

  • 0

I have a shape file, and I want to show it on the web by using leaflet (http://leaflet.cloudmade.com/). Since leaflet only support geoJSON, I should change the shp file into geoJSON. It is easy since I can use “save as” capability in Quantum-GIS.

Although I can use geojson as database (by reading, edit and writing the file programmatically), I think it is better to use the “real” database. My-SQL is the most popular one, and it support spatial data, so I decide to use MySQL.

The scenario is:

  1. Change shp into MySQL (I use ogr2ogr and just simply run this command: ogr2ogr -f “MySQL” MySQL:”geo,user=root,host=localhost,password=toor” -lco engine=MYISAM airports.shp)
  2. Fetch MySQL database into geojson <– here is the problem
  3. Using ajax to get the geojson and change the layout <– this should be easy, I’m good with JQuery

There is a column in My MySQL table which its type is “GEOMETRY”, Look the table definition below:

CREATE TABLE IF NOT EXISTS `airports` (
  `OGR_FID` int(11) NOT NULL AUTO_INCREMENT,
  `SHAPE` geometry NOT NULL,
  `cat` decimal(10,0) DEFAULT NULL,
  `na3` varchar(80) DEFAULT NULL,
  `elev` double(32,3) DEFAULT NULL,
  `f_code` varchar(80) DEFAULT NULL,
  `iko` varchar(80) DEFAULT NULL,
  `name` varchar(80) DEFAULT NULL,
  `use` varchar(80) DEFAULT NULL,
  UNIQUE KEY `OGR_FID` (`OGR_FID`),
  SPATIAL KEY `SHAPE` (`SHAPE`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=77 ;

Is there any way to change such a table into geojson format?
(I prefer the easy way, but if there is not, just change the column into array like is acceptable)

EDIT:
I use geophp written by phayes.
https://github.com/phayes/geoPHP/wiki/Example-format-converter.
This solves the main problem. Only need to a bit mess up with adding feature etc.
Any easier solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:11:38+00:00Added an answer on June 6, 2026 at 12:11 am

    While there may not be a direct method to convert from a mysql spatial entity to geojson, you can try the following:

    • get the WKT (Well Known Text) of the entity. (MySQL Reference)
    • convert from WKT to geojson (Done in perl, although you should be able to find it in other languages or write your own in javascript);

    Note that just calling jsonEncode() on the entity, as others have suggested, will not yeild geoJson.

    My personal suggestion, which does not directly answer your question, would be to store the data in the format you need it retrieved in. It will reduce the overhead required to process the data every time you need it.

    The easiest way to do this is to store the geojson in plain text as you suggested. If, for whatever reason, you also need the geometry stored in native format, you can store it in another column. The only downside is keeping the two columns in sync.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using visual web developer express 2010, I want to display a shape file and
I want to create a single shape file from multiple mxd's that have multiple
I do have a xml file located at : http://api.wunderground.com/api/adaebe40743a9ca6/geolookup/conditions/forecast/q/India/Pilani.xml Now i want to
I have a font in ttf file and want to generate SVG with text
I have an ASP.NET/C# web app and I want to add the capability to
I have a couple shape files that I want to plot some scatterplot data
I have this shape defined in an xml file, and need to create it
I have a shape file with two different region with 12 sub region each.I
I have a .xaml file and a .cs file that share value with Binding.
I have an activity that when users press share on a file it would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.