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 7944617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:36:19+00:00 2026-06-04T00:36:19+00:00

From a geospatial column in mysql I’m getting the following string-value which I want

  • 0

From a geospatial column in mysql I’m getting the following string-value which I want to convert into an array. Ultimate goal is to convert it to geoJSON.

POLYGON((4.885838 52.388063,4.891061 52.388381,4.890973 52.382909))

This string has 3 coordinate pairs with the x and y coordinate separated by a space and the pairs separated with a comma. The exact number is not known and variable. Also the POLYGON can differ to three different settings.

With my little knowledge of reg. expressions I came up with this:

$pat = '/^(POLYGON|LINESTRING|POINT)(\(\() (.....) (\)\))$/';
preg_match($pat, $str, $matches);

With the part of the coordinates with the double brackets as an uncertain part.

Could anyone help me with this?

edit Ultimately the resulting array should look like this:

$array['type'] = POLYGON | LINESTRING ....
$array['coordinates'] = array of all the coordinates.
  • 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-04T00:36:21+00:00Added an answer on June 4, 2026 at 12:36 am

    I think it’s easier and more maintainable to just use explode and array_map on the coordinate string:

    $coordString = $matches[3];
    $coordinates = array_map(function($e) { return explode(' ', $e); },
                             explode(',', $coordString));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is for Mysql geospatial-extension experts. The following query doesn't the result that
From a user report, 'when editing foo. textboxBar allows special characters which produce a
from my small knowlegde from java se i want to try a tutorial on
From http://www.doc.ic.ac.uk/teaching/projects/Distinguished03/AndrewSuffield.pdf : #include <string.h> struct x { char s[10]; int a[4]; }; void
from the table realestate I want to get the number of records where the
From security reasons, is it worth encrypting user emails before putting them into the
From the agenda view, I want to press a key and remove the SCHEDULED:
From JSP file accessed another JSP file which acts like java class, this used
From my xhtml file: <h:inputTextarea value=#{newPostForm.post.body}> <f:converter converterId=NL2BRConverter /> </h:inputTextarea> From my java file:
From 19 Deadly Sins of Software Security ; The following code is the poster

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.