2016-01-20 21 views
7

Sto cercando di ottenere in formato linee che GeoJSON utilizzando impressionante libreria PHP-Database-GeoJSON da qui https://github.com/bmcbride/PHP-Database-GeoJSON ma per ora senza alcuna fortunaOttenere GeoJSON stringa lineare da MySQL dati WKT geometria

ho avuto successo con chiamando semplici punti da MySQL tabella usando quella libreria ma con linee e poligoni la storia è un po 'diversa.

In primo luogo, ho creato tabella con il campo della geometria, qualcosa di simile:

-- phpMyAdmin SQL Dump 
-- version 4.4.6 
-- http://www.phpmyadmin.net 
-- 
-- Host: localhost 
-- Generation Time: Jan 20, 2016 at 10:12 PM 
-- Server version: 5.6.24 
-- PHP Version: 5.6.8 

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 
SET time_zone = "+00:00"; 


/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */; 
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */; 
/*!40101 SET @[email protected]@COLLATION_CONNECTION */; 
/*!40101 SET NAMES utf8 */; 

-- 
-- Database: `web_gis` 
-- 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `wkt_linija` 
-- 

DROP TABLE IF EXISTS `wkt_linija`; 
CREATE TABLE IF NOT EXISTS `wkt_linija` (
    `id` int(11) NOT NULL, 
    `oznaka` varchar(50) NOT NULL, 
    `opis` varchar(200) NOT NULL, 
    `sirina` varchar(200) NOT NULL, 
    `podloga` varchar(200) NOT NULL, 
    `mo` varchar(200) NOT NULL, 
    `geometry` geometry NOT NULL 
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; 

-- 
-- Dumping data for table `wkt_linija` 
-- 

INSERT INTO `wkt_linija` (`id`, `oznaka`, `opis`, `Å¡irina`, `podloga`, `mo`, `geometry`) VALUES 
(1, 'K-8', 'D206 - Vulica - Kraljevec - Horvati - Kordej - S1', '5 m', 'Asfalt-makadam', 'Kostel', '\0\0\0\0\0\0\0¿\0\0\0§5l¹r/@##Lê[email protected]ëŸëÑr/@,†‰©[email protected]¤úâèr/@*éöŠ[email protected]Ç4sùr/@õYd\[email protected]}VHÉs/@·[email protected]©`›\Zs/@ÜdÏ[email protected]ß%s/@}*†[email protected]®ñ„/s/@óÅ,Þ[email protected]Ùª³ã7s/@w!™cÿ[email protected]ÝAs/@zOöü[email protected]‘t·ÀMs/@Ê.›Öú[email protected]…_e]s/@w;yù[email protected]­‰tts/@š¢ýö[email protected]Ñ„»”s/@S`ùåô[email protected]±å¡´s/@»÷‡ó[email protected]ÉSÔÏs/@Ê[email protected]ò[email protected]Ê„Sñs/@<zò[email protected]¥HÖHt/@Ï\n±Ïñ[email protected]/@«ôÚð[email protected]Þôz(t/@äò=î[email protected]׎¬/9t/@‚áoé[email protected]•‡\0Kt/@ûq\0ä[email protected]ª†Xt/@n”TTß[email protected]%-šmjt/@ÒÃ|‡Û[email protected] =‰t/@\Zñ‡Õ[email protected]‚~bÉt/@bnåÈ[email protected]’Oƒøt/@Ñ»oÙ¿[email protected]¶¡ãu/@F+Bº[email protected]ðèð9u/@õO‘¶[email protected]õmeVu/@íójB´[email protected]¬íæ_gu/@’''™²[email protected]žº’îou/@›CØ°[email protected]è1Bou/@Ž­[email protected]è’ju/@ýEŒª[email protected]|¯Yu/@#H|L¦[email protected]ÏHu/@ò†M¢[email protected]¹¡_„0u/@ÑÞ„ž[email protected]ø*È>/u/@ä]*Rž[email protected]«®\0\ru/@› šš[email protected]Ãbát/@m«NÈ—[email protected][÷¾t/@)hNè“[email protected]…!E‹t/@‘FÕŽ[email protected][$ïtbt/@ŠuŠ[email protected]#dJt/@c€ÌD‡[email protected]윔Î.t/@žZ.†[email protected]/bt/@qx›\Z†[email protected]¶´·¯òs/@iŒ¶&†[email protected]×Í>¼Õs/@Ãís³†[email protected]ÃW‡@µs/@RqÈ[email protected]Ä…¡s/@B^µŠ[email protected]Ò3©‘s/@9Tþ5‰[email protected]å»Øáˆs/@†ÍÀ†[email protected]£ã…s/@S»Ìƒ[email protected])jm†s/@(E瘀[email protected]üÊqцs/@\0{\[email protected]ÂÄas/@Ë/c¸[email protected]¬¹…÷‘s/@[email protected]’€Ms/@c¹[email protected]©Æ+̤s/@àv¬[email protected]} ±s/@°{§,[email protected]»Bi,¿s/@ÆÇúœ[email protected]æ1Ïs/@JJ‹#`[email protected]ø;·rÑs/@''>v¦[email protected]§`]Ös/@òc±][email protected]\Z¯žØs/@ZÂ`Ë\\[email protected]/à/?Ýs/@µeò[email protected]ïú®ùës/@³¾â¿[email protected]®žéñs/@M.ö±[email protected]ÿ^òs/@ Í[email protected]<Éhýs/@rÙ–[email protected]¸*Bt t/@<Ÿˆ[email protected]Þù)t/@ËGò>[email protected]ûÄj(t/@A©Â[email protected]@¡›ãÕ-t/@:í[email protected],5t/@Ÿ²@;[email protected]¬t*Bt/@ ¤‘[email protected]!zKt/@L¬ž[email protected]lj}Ut/@Ы¼¹[email protected]}Ö¼\\wt/@›É¤û[email protected]&4œt/@ÖD¨([email protected]æš±t/@‘&¡#[email protected]âq^³±t/@8Ûe›#[email protected]“º»MÇt/@ï  [email protected]‘£ßt/@™(FÏ[email protected]ª8W÷t/@¿¼¹[email protected]íQñGu/@º3æ[email protected]²Þ2Ýu/@_¶L¶[email protected]âR€u/@j|æ’[email protected]''‚Öau/@½-Þù[email protected]ö¹­)u/@óèP‡[email protected]/@È3¤[email protected]˜Ôî%u/@Û$Í[email protected]‘ðu/@<˜[email protected]þBu/@=JPý[email protected]¾ß"u/@K›tãú[email protected]ºw¤#u/@†‘ËÁú[email protected]]N,u/@“;­Gù[email protected]æß?u/@B_Lö[email protected]ÌvmÝVu/@áó×ó[email protected]˜§Ev[u/@¥2Äð[email protected]@TÏl_u/@â+qgí[email protected]ɽ\Zeu/@[]a…ç[email protected]:ø )gu/@g-á[email protected]é’du[u/@>6wMÞ[email protected]úmNƒUu/@­V¦óÙ[email protected]ˆøÆQu/@ÔKÿÕ[email protected]¥K?MQu/@–ÑKÒ[email protected]œu~Vu/@¹Ã[õÎ[email protected]­È­ø]u/@ ÛñoÌ[email protected]¦Åhu/@ÙŠ˜,Ê[email protected]¤DÕ£wu/@Yá¿È[email protected]+\Z‰u/@a¦­Ç[email protected]\r¤u/@׬œ?Æ[email protected] €ì¸u/@R½JJÅ[email protected]}qaÂu/@èjûÄ[email protected]¢U§½Èu/@Í-)Â[email protected](Íu/@è.P¿[email protected]`ûfåÑu/@ÂÁ¸F»[email protected]þ¨²Öu/@œ™? ¸[email protected]–Çû’Þu/@‰Œû]¶[email protected]ÏÀéu/@3%´[email protected]Ý]üu/@ß6$±[email protected]]‘ó v/@ ©Zð®[email protected]+v/@¥Éæ¬[email protected]¤]¶v/@Žòר[email protected]˜.ôæ\Zv/@®÷—Š¤[email protected] v/@"á\0M—[email protected]Ðitv/@ׄ½’[email protected]ðüv/@Ý5­BŽ[email protected]µ3 \nv/@é¨þ‹[email protected]/@øP{‰ˆ[email protected];$P÷u/@ÏV’>„[email protected]ëàrYëu/@˜wÒ[email protected]à°y!Ýu/@ðÿ[email protected]ÐfÃu/@g"òá[email protected]¹Œ­u/@kU¸[email protected]䉽;šu/@‰ôó™[email protected]ÿQJu/@Üâ[email protected]¶‰Š)‰u/@F>#[email protected]´ú€u/@û]Ÿª[email protected]ˆÚzu/@0Eó[email protected]Á¼©pu/@òÔ¦[email protected]€]"X[u/@\0³''[email protected]ÖæˆMu/@Ç>\\`[email protected]Ð\n|–Fu/@!¤……^[email protected]''Ú9ôDu/@×Oi\\[email protected]íµ PFu/@DmÅ^[email protected]¨®ÍHu/@¡žî[email protected]_¶WéJu/@Ål [email protected]£y¯OMu/@e¡Æ[email protected]™3¯äKu/@[email protected],šlAHu/@bä;‰[email protected]^J+îCu/@¾ä[email protected]æˆO\\=u/@y^ßþ[email protected]Î2¿.u/@‘šþ[email protected]œ—7Ru/@Óœ[email protected]˜¡q‹u/@+ê©ñ[email protected]ÖŒ„u/@³ì%–[email protected]÷fáÔ u/@%ó\Z|[email protected]|´zºu/@&í“´[email protected]"¬+u/@OÉó\\)[email protected]Þ_µ™u/@lW™%[email protected]#§G[)u/@õŽ(''[email protected]$t/“4u/@[email protected]/;^>u/@l”Â[email protected]¤¿²¯Lu/@³ê‰[email protected]ß|Smau/@^[email protected]Ê »Çuu/@ÃÖ¤Ã[email protected]”1î‡u/@èÐ…\[email protected]úHd•u/@/U€[email protected]>bo¿¡u/@¢ôeö[email protected]ß®u/@&\nP-\[email protected]ï‹}r·u/@Tñ-ºü[email protected]~ø¹u/@œ^Ì6ú[email protected]²eóºu/@걓\n÷[email protected]~‹W)¸u/@bÍô[email protected]ø±u/@Üa*Ôò[email protected]#k¨u/@müñ[email protected]ñ®šu/@i(q‹ñ[email protected]ŸVˆu/@Š"Èð[email protected]ÿ•ru/@MðFwï[email protected]Éúeäbu/@i¶Öí[email protected]à;Uu/@ZÛ:Ðë[email protected]ˆ+ìOu/@‘D4é[email protected]/@z 6æ[email protected]ä€3sHu/@èY;ã[email protected]ÒŸng>u/@x9„9à[email protected]"‚ƒX1u/@3òïÝ[email protected]/@ïv\n–Û[email protected]¯u/@%F\0Ø[email protected]—ÍH0ôt/@‰œìÄÔ[email protected]'); 

-- 
-- Indexes for dumped tables 
-- 

-- 
-- Indexes for table `wkt_linija` 
-- 
ALTER TABLE `wkt_linija` 
    ADD PRIMARY KEY (`id`); 

-- 
-- AUTO_INCREMENT for dumped tables 
-- 

-- 
-- AUTO_INCREMENT for table `wkt_linija` 
-- 
ALTER TABLE `wkt_linija` 
    MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2; 
/*!40101 SET [email protected]_CHARACTER_SET_CLIENT */; 
/*!40101 SET [email protected]_CHARACTER_SET_RESULTS */; 
/*!40101 SET [email protected]_COLLATION_CONNECTION */; 

Ecco immagine. Non so perché, ma quando ho esportato la tabella ho ottenuto strani simboli nella riga della geometria, qualcosa del genere "/ @ ‰ œìÄÔG @". È coz Ho selezionato la funzione GeomFromText durante la creazione del campo della geometria?

Picture example

La vera domanda è questa. Quando sto usando questo blocco di codice per estrarre i dati da MySQL e convertire in GeoJSON:

<?php 

include_once('geoPHP/geoPHP.inc'); 

$conn = new PDO('mysql:host=localhost;dbname=web_gis;charset=utf8','neven','gis',array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); 

$sql = 'SELECT *, geometry AS wkt FROM wkt_linija'; 

$rs = $conn->query($sql); 
if (!$rs) { 
    echo 'An SQL error occured.\n'; 
    exit; 
} 

$geojson = array(
    'type'  => 'FeatureCollection', 
    'features' => array() 
); 

while ($row = $rs->fetch(PDO::FETCH_ASSOC)) { 
    $properties = $row; 

    unset($properties['wkt']); 
    unset($properties['geometry']); 
    $feature = array(
     'type' => 'LineString', 
     'geometry' => json_decode(($row['wkt'])), 
     'properties' => $properties 
    ); 

    array_push($geojson['features'], $feature); 
} 
header('Content-type: application/json'); 
echo json_encode($geojson, JSON_NUMERIC_CHECK); 
$conn = NULL; 
?> 

campo Geometria viene ignorato e ottengo risultati senza qualsiasi geometria, in questo modo:

{"type":"FeatureCollection","features":[{"type":"LineString","geometry":null,"properties":{"id":1,"oznaka":"K-8","opis":"D206 - Vulica - Kraljevec - Horvati - Kordej - S1","sirina":"5 m","podloga":"Asfalt-makadam","mo":"Kostel"}}]} 

e dovrebbe avere qualcosa del genere se non sbaglio:

{"type": "FeatureCollection","features": [ 
{ "type": "Feature", "properties": { "OBJECTID": 857, "OZNAKA": "K-8", "OPIS": "D206 - Vulica - Kraljevec - Horvati - Kordej - S1", "�IRINA": "5", "PODLOGE": "Asfalt-makadam", "DULJINA": 2.714530, "SHAPE_Leng": 2714.529879, "JLS": "Pregrada", "MO": "Kostel" }, "geometry": { "type": "LineString", "coordinates": [ [ 15.724070907944066, 46.188443457771676 ], [ 15.724257815619874, 46.188344185018963 ], [ 15.724433034034641, 46.188218470155633 ], [ 15.72455940264949, 46.188111948013024 ], [ 15.724699297027877, 46.187990209886379 ], [ 15.724812369870586, 46.187860416649634 ], [ 15.72489216542548, 46.187729597634622 ], [ 15.72497191850638, 46.187587520467694 ], [ 15.725035777742436, 46.18748135544859 ], [ 15.725105549827283, 46.187407292181923 ], [ 15.725202581781817, 46.187342477581822 ], [ 15.725321929846059, 46.187288459964229 ], [ 15.725497857862772, 46.187225059863707 ], [ 15.725739143267136, 46.18716120411468 ], [ 15.725983191502424, 46.187106791868665 ], [ 15.726194987431329, 46.187080890038104 ], [ 15.726450533317252, 46.187073593715894 ], [ 15.726602817685782, 46.187066995092771 ], [ 15.726732946011916, 46.187037820050442 ], [ 15.726868107327785, 46.186958068465223 ], [ 15.726998796285825, 46.18681143294458 ], [ 15.72713472037392, 46.186645560888834 ], [ 15.727237900023473, 46.186502972887737 ], [ 15.727374482221942, 46.186387000961659 ], [ 15.727609563629075, 46.186189834001382 ], [ 15.72809649660417, 46.185818387861914 ], [ 15.728458503155057, 46.185542277867746 ], [ 15.728743661394422, 46.185371657495338 ], [ 15.728957680163198, 46.185259021798828 ], [ 15.729172360784085, 46.185188581679405 ], [ 15.72930431074095, 46.185137873121803 ], [ 15.729369597827198, 46.185060721013734 ], [ 15.729363091545522, 46.184984028820601 ], [ 15.729328718981932, 46.184892184228353 ], [ 15.729199870961573, 46.184762535747971 ], [ 15.729071126927163, 46.184640592675251 ], [ 15.728885780977054, 46.184525116727102 ], [ 15.728876077589561, 46.184519072234053 ], [ 15.728614827463138, 46.184405640049697 ], [ 15.728282035417173, 46.184319532788187 ], [ 15.728019456787038, 46.184201277050597 ], [ 15.727625044660053, 46.184046453459025 ], [ 15.727313665573254, 46.183902676002639 ], [ 15.72713005952758, 46.183815574507001 ], [ 15.726919608727677, 46.183782381293177 ], [ 15.726687496419437, 46.183780027306859 ], [ 15.726460925269162, 46.183781470427512 ], [ 15.72624004618312, 46.183798247915114 ], [ 15.725992218514767, 46.183861189085874 ], [ 15.725841694066393, 46.183920515406967 ], [ 15.725715865521043, 46.183874844726638 ], [ 15.725653703409941, 46.18379975520206 ], [ 15.725630852584601, 46.18370970853416 ], [ 15.725634974679185, 46.183611977505564 ], [ 15.725637955799805, 46.183427810892681 ], [ 15.725685548243181, 46.183341072493555 ], [ 15.725723013948333, 46.183206133168625 ], [ 15.725809501193257, 46.183107700844715 ], [ 15.725866680473091, 46.183003917087035 ], [ 15.725960645833988, 46.182866651324161 ], [ 15.726067912911608, 46.182727453662253 ], [ 15.726190146802059, 46.182621424687184 ], [ 15.726207337253058, 46.182606513725027 ], [ 15.726244838952267, 46.182546780957537 ], [ 15.726262053423898, 46.182519361730286 ], [ 15.726297354311184, 46.182371391634128 ], [ 15.726409723863496, 46.182212815966885 ], [ 15.726455021424353, 46.182089085774898 ], [ 15.726458519588704, 46.1820795299138 ], [ 15.726542714259828, 46.182008813530857 ], [ 15.726634629323016, 46.181917731008497 ], [ 15.726792632784449, 46.181770199109074 ], [ 15.726870857759003, 46.181649656342877 ], [ 15.726912197145625, 46.181557050493623 ], [ 15.72696727853892, 46.181495749681858 ], [ 15.727067305319169, 46.181413846381595 ], [ 15.727138343041192, 46.181354299035405 ], [ 15.727214739777891, 46.181296555637914 ], [ 15.727473161746497, 46.181121306860597 ], [ 15.727754239724749, 46.180928261966685 ], [ 15.727917519198943, 46.180774825857164 ], [ 15.727918248442567, 46.180774140104802 ], [ 15.728083066145052, 46.180681243365932 ], [ 15.728268727778216, 46.180597218758699 ], [ 15.728449559847867, 46.180521693889652 ], [ 15.728548286636363, 46.180459010508869 ], [ 15.728575622997003, 46.180441653687687 ], [ 15.728626260838556, 46.180345881025303 ], [ 15.728632981715306, 46.180266602979351 ], [ 15.728631308037603, 46.180130877024475 ], [ 15.728609388865232, 46.180042767469388 ], [ 15.72863119640742, 46.179925578113505 ], [ 15.728675382393831, 46.179736203157688 ], [ 15.728754103415818, 46.179605518578782 ], [ 15.728781671000469, 46.179531509339164 ], [ 15.728787555327612, 46.17952749671808 ], [ 15.728853653803199, 46.179482421480451 ], [ 15.729002926254177, 46.179391428482766 ], [ 15.729178351986228, 46.179316475034064 ], [ 15.729213424685256, 46.17922260735417 ], [ 15.729243660267571, 46.179119997271997 ], [ 15.729286990802217, 46.178940460721343 ], [ 15.729302693271269, 46.178746820197198 ], [ 15.729213398482402, 46.178659136971405 ], [ 15.729168036769796, 46.178526359767922 ], [ 15.729134552992278, 46.178405644044375 ], [ 15.72913590810442, 46.178292729463621 ], [ 15.729175521649999, 46.178190870100885 ], [ 15.729232569898466, 46.178113930791596 ], [ 15.729312949540265, 46.178044867023068 ], [ 15.729428405555446, 46.177993744555984 ], [ 15.729561627668394, 46.177968698730346 ], [ 15.729767239109798, 46.177925063611546 ], [ 15.729926481857566, 46.177895819181359 ], [ 15.729998631576199, 46.177859065783025 ], [ 15.730047156025481, 46.177800306667997 ], [ 15.730080843602126, 46.177713416007506 ], [ 15.730117005177533, 46.177590217793764 ], [ 15.730153622997474, 46.177509337477403 ], [ 15.730213731036013, 46.177440402819293 ], [ 15.730294124893048, 46.177372576295973 ], [ 15.730441029813072, 46.177280928037128 ], [ 15.730544656814056, 46.177213711041304 ], [ 15.730607373995639, 46.177126634301466 ], [ 15.730649660998102, 46.177027590548377 ], [ 15.730673997218489, 46.176896404459839 ], [ 15.730686159036875, 46.176492333821685 ], [ 15.730678213040187, 46.176331131495026 ], [ 15.730644702457511, 46.17621644456424 ], [ 15.730591136985689, 46.176118015618904 ], [ 15.730532059952845, 46.176041779721288 ], [ 15.730402473852994, 46.175910779432904 ], [ 15.730311198495164, 46.175818660514039 ], [ 15.730202718834732, 46.175734675489252 ], [ 15.730003845739928, 46.175625079374008 ], [ 15.729839704148707, 46.175515260702774 ], [ 15.729692332160035, 46.175372356528051 ], [ 15.729618528196623, 46.175276053085071 ], [ 15.729562090073937, 46.175183670242902 ], [ 15.729499659065965, 46.175069167915318 ], [ 15.72944644429414, 46.1749969661563 ], [ 15.729370166749847, 46.174936968289231 ], [ 15.729212526507354, 46.174871463188538 ], [ 15.729107168367774, 46.174815683654337 ], [ 15.729054167405963, 46.17475956941076 ], [ 15.729041702329665, 46.17469517134213 ], [ 15.72905208551216, 46.174602362060369 ], [ 15.729071071151182, 46.174497439541717 ], [ 15.729087154347495, 46.174396528594606 ], [ 15.72910546319037, 46.174248531959883 ], [ 15.729094644915493, 46.17408531172007 ], [ 15.729066891200169, 46.17396655487461 ], [ 15.729033892425999, 46.173890151499549 ], [ 15.728983769139131, 46.173827990595733 ], [ 15.728872275277265, 46.173739313429117 ], [ 15.728754586492691, 46.173621131114167 ], [ 15.72865710985279, 46.173490722623988 ], [ 15.72860349855311, 46.173388260381579 ], [ 15.728590633883398, 46.173293603095125 ], [ 15.728612735251083, 46.173208782415074 ], [ 15.728646626318611, 46.173137301479635 ], [ 15.728726199522438, 46.173007798074508 ], [ 15.728831150528611, 46.172825712970656 ], [ 15.728916739981351, 46.172712260059178 ], [ 15.72899145576932, 46.172630617446742 ], [ 15.729100695199868, 46.172549311964211 ], [ 15.729258934441928, 46.172437431420562 ], [ 15.729414216596428, 46.172325568664313 ], [ 15.729546276642203, 46.172213855113853 ], [ 15.729655393513083, 46.172107398664927 ], [ 15.729749662729883, 46.171995925696379 ], [ 15.729846939429743, 46.171880401689393 ], [ 15.729915216279521, 46.171775124009088 ], [ 15.729934468671422, 46.171698426999882 ], [ 15.729941946170445, 46.171601602665604 ], [ 15.729920665680535, 46.17153322935043 ], [ 15.729873420226953, 46.171473046011414 ], [ 15.729800556251329, 46.171447282199416 ], [ 15.7296957654536, 46.171433859112604 ], [ 15.729553262542693, 46.171410576691585 ], [ 15.729389846247617, 46.171370420110726 ], [ 15.729270112465558, 46.171320761745136 ], [ 15.729164786156741, 46.171258953798954 ], [ 15.729123053626395, 46.17117657711163 ], [ 15.729104461899636, 46.171087984683425 ], [ 15.729068374669119, 46.170993474941326 ], [ 15.728991729978507, 46.170905294001329 ], [ 15.728892103245986, 46.170835384142627 ], [ 15.728746006764606, 46.170763735875759 ], [ 15.728573253271504, 46.170655965932646 ], [ 15.728425511252494, 46.170555701764052 ] ] } } 
] 
} 

Non so cosa mi manca. È qualcosa nel blocco di codice .php, o ho fallito con la creazione di una tabella e la selezione di una funzione sbagliata durante la creazione di un campo di geometria, davvero non lo so.

Grazie per l'aiuto o le critiche costruttive sulla domanda.

UPDATE

Anche quando compreso questo blocco di codice in un file .php di cui sopra (copiato da qui https://github.com/phayes/geoPHP

<?php 
include_once('geoPHP/geoPHP.inc'); 

function wkt_to_json($wkt) { 
    $geom = geoPHP::load($wkt,'wkt'); 
    return $geom->out('json'); 
} 
... 

ottengo preavviso

Notice: Undefined offset: 1 in C:\xampp\htdocs\PHP-GEOJSON\MySQL_LINIJA\geoPHP\lib\adapters\WKT.class.php on line 23

e

fatale errore

Fatal error: Call to a member function out() on null in C:\xampp\htdocs\PHP-GEOJSON\MySQL_LINIJA\line.php on line 16

risposta

0

Con un po 'di aiuto (ad essere sinceri sono stati davvero utili) Finalmente ho capito.

Quindi, ecco l'accordo. Nel campo della geometria (MySQL) ho usato la funzione GeomFromText e per valore utilizzato formato come questo:

'LINESTRING(15.710658104182732 46.20239760250581,15.710776991330624 46.202150210442475,15.710822931962284 46.20192080948476,15.710831682524589 46.20165203949391,15.710829367910724 46.201478170096806,15.710778748807499 46.201345541255364,15.710749581923572 46.20098083884202,15.710768970490234 46.200904345256404,15.710812698319572 46.200819215538004,15.710877059895306 46.2007537567,15.710904378497835 46.20066024293927,15.710912159473589 46.20039950452849,15.710894434522887 46.20028929894646,15.710844620624444 46.20021889590132,15.710754497671333 46.20018268546197,15.710619472746819 46.200141098973376,15.710468078447006 46.20009395676996,15.710300020035252 46.20001863058078,15.71013294549417 46.200019670809,15.710063999207861 46.20004555880265,15.709954779718144 46.20010846583362,15.709825367334812 46.200185643990416,15.709740155452225 46.20021445995833,15.7095978600008 46.20024080222257,15.709435298637604 46.20027575661596,15.709362166147757 46.20029318215561,15.709321746574172 46.200318892298654,15.70924501465025 46.2003731121604,15.709176908852976 46.20046404855626,15.70912593824907 46.2006199379506,15.709082098558873 46.200696581456555,15.709041746284855 46.20072794679033,15.708980768498824 46.20073963902233,15.708833996835912 46.20073489545015,15.70867866945619 46.200699088541356,15.708441515485225 46.200638334448556,15.70831071551633 46.200608030417,15.708025541089574 46.20061546014786,15.707936251453559 46.200644298279066,15.707786277558592 46.20070745795111,15.707623895583048 46.200756550625464,15.707461001390076 46.20076604727856,15.707318051223131 46.20074147497647,15.707207479007135 46.20069973463324,15.707066607106702 46.20060074856272,15.70664318279083 46.20030616960038,15.705882062458974 46.19972242368199,15.70511493399327 46.19906980655475,15.704648034594763 46.1987219944351,15.70450919728616 46.19858019598824,15.704291928591257 46.19833188738757,15.704161428771785 46.198172204352296,15.703537141003846 46.19756976517491,15.703216667780048 46.197286427418,15.702992669467902 46.197180815640245,15.702837928060974 46.19713421658259,15.702717672096156 46.19710523755276,15.70259748698871 46.19708220158732,15.701539642071204 46.19672612421737,15.701342168546992 46.19668573136494,15.701050429965196 46.19663997213334,15.700655562790246 46.196565125734026,15.700286457978665 46.19649606343836,15.700088834888449 46.196443782082085,15.699934103148394 46.196397179030086,15.699769973735597 46.1962852481137,15.699587967151555 46.19611398852277,15.699336247021442 46.19584804901749,15.699059302528688 46.19561793070997,15.698759082297304 46.195383057970396,15.698344688297988 46.195118114465565,15.698137525323025 46.19498861375236,15.698007207286828 46.1948408097566,15.697833392097015 46.19463977545958,15.697738075051644 46.19455119870973,15.697513417413118 46.19439208391872,15.696752249589233 46.19379044428983,15.696406296846584 46.19351913197643,15.69616377139154 46.19330068008819,15.695964208560289 46.19309385821015,15.695790263799942 46.19288093427891,15.695446508778891 46.192414313313975)',4326 

Sembra che i dati in tabella di MySQL è memorizzato in WKB, ma in qualche modo quando ho vista è in fase automaticamente tradotto in WKT! ?

Io non sono davvero sicuro perché è che o come accade, ma per estrarre i dati dalla tabella di MySQL e convertire in GeoJSON ho usato la biblioteca geoPHP con queste righe di codice:

// library downloaded from here https://github.com/phayes/geoPHP 
include_once('../geoPHP/geoPHP.inc'); 

// function for calling wkb_to_json processor 
function wkb_to_json($wkb) { 
    $geom = geoPHP::load($wkb,'wkb'); 
    return $geom->out('json'); 
} 

// checking if databasestring is UTF8 
$conn = new PDO('mysql:host=localhost;dbname=web_gis;charset=utf8','neven','gis',array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); 

// using AsBinary on geometry field 
// Converts a value in internal geometry format to its WKB representation and returns the binary result 
$sql = 'SELECT *, AsBinary(geometry) AS wkb FROM wkt_line'; 

$rs = $conn->query($sql); 
if (!$rs) { 
    echo 'An SQL error occured.\n'; 
    exit; 
} 

$geojson = array(
    'type'  => 'FeatureCollection', 
    'features' => array() 
); 

while ($row = $rs->fetch(PDO::FETCH_ASSOC)) { 
    $properties = $row; 

    unset($properties['wkb']); 
    unset($properties['geometry']); 
    $feature = array(
     'type' => 'Feature',//outer feature 
     'geometry' => json_decode(wkb_to_json($row['wkb'])), 
     'properties' => $properties 
    ); 

    array_push($geojson['features'], $feature); 
} 

header('Content-type: application/json'); 
echo json_encode($geojson, JSON_NUMERIC_CHECK); 
$conn = NULL; 

e ha funzionato! Divertiti ...

1

La mia semplice soluzione utilizza MySQL per convertire le geometrie POINT e LINESTRING in GeoJSON. Nel mio caso una singola tabella memorizza punta e stringa lineare geometrie ma questo potrebbe essere facilmente esteso per poligoni per singolo pezzo e multi-punti:

SELECT 
    IF(LENGTH(AsText(network_objects.geometry)) = 0, 
    'null', 
    IF(LOCATE('POINT',AsText(network_objects.geometry)), 
    CONCAT('{"type": "Point", "coordinates":', 
    REPLACE(
     REPLACE(
      REPLACE(
       AsText(network_objects.geometry), ' ', ',' 
      ), 
      'POINT(', '[' 
     ), ')', ']' 
    ),'}' 
), 

    IF(LOCATE('LINESTRING', AsText(network_objects.geometry)), 
    CONCAT('{"type": "LineString", "coordinates":', 
    REPLACE(
     REPLACE(
      REPLACE(
       REPLACE(
        AsText(network_objects.geometry), ',' ,'],[' 
       ), 
       ' ',',' 
      ), 
      'LINESTRING(', '[[' 
     ),')',']]' 
    ),'}'), 
    'null' 
) 
    ) 
) as geometry_type_string 
FROM geometry_table; 

Ciò produrrà il valore per la "geometria": -property di un oggetto GeoJSON come

{"type": "LineString", "coordinates":[[15.42324565,60.38242968],[15.42307974,60.38252172]]} 
Problemi correlati