/ Check-in [2653bedd]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The translation in and out of GeoJSON automatically adds or removes the redundant last vertex, as necessary.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | geojson
Files: files | file ages | folders
SHA3-256:2653bedd9f8237d9ddef533a05e161a6afe6fa4af86fac47407b3df09dc2a9eb
User & Date: drh 2018-05-09 15:27:35
Context
2018-05-11
14:00
Make sure the open_db() routine in the CLI does not invoke access() with a NULL filename. check-in: 2b8fd3b4 user: drh tags: geojson
2018-05-09
15:27
The translation in and out of GeoJSON automatically adds or removes the redundant last vertex, as necessary. check-in: 2653bedd user: drh tags: geojson
15:20
Fix the geopoly_json() SQL function so that it works. check-in: 236588d5 user: drh tags: geojson
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/geopoly.c.

   219    219         }
   220    220         if( geopolySkipSpace(&s)==',' ){
   221    221           s.z++;
   222    222           continue;
   223    223         }
   224    224         break;
   225    225       }
   226         -    if( geopolySkipSpace(&s)==']' ){
   227         -      int nByte = sizeof(GeoPoly) * (s.nVertex-1)*2*sizeof(GeopolyCoord);
   228         -      GeoPoly *pOut = sqlite3_malloc64( nByte );
   229         -      int x = 1;
          226  +    if( geopolySkipSpace(&s)==']' && s.nVertex>=4 ){
          227  +      int nByte;
          228  +      GeoPoly *pOut;
          229  +      int x = (s.nVertex-1)*2;
          230  +      if( s.a[x]==s.a[0] && s.a[x+1]==s.a[1] ) s.nVertex--;
          231  +      nByte = sizeof(GeoPoly) * (s.nVertex-1)*2*sizeof(GeopolyCoord);
          232  +      pOut = sqlite3_malloc64( nByte );
          233  +      x = 1;
   230    234         if( pOut==0 ) goto parse_json_err;
   231    235         pOut->nVertex = s.nVertex;
   232    236         memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeopolyCoord));
   233    237         pOut->hdr[0] = *(unsigned char*)&x;
   234    238         pOut->hdr[1] = (s.nVertex>>16)&0xff;
   235    239         pOut->hdr[2] = (s.nVertex>>8)&0xff;
   236    240         pOut->hdr[3] = s.nVertex&0xff;
................................................................................
   320    324     GeoPoly *p = geopolyFuncParam(context, argv[0]);
   321    325     if( p ){
   322    326       sqlite3 *db = sqlite3_context_db_handle(context);
   323    327       sqlite3_str *x = sqlite3_str_new(db);
   324    328       int i;
   325    329       sqlite3_str_append(x, "[", 1);
   326    330       for(i=0; i<p->nVertex; i++){
   327         -      sqlite3_str_appendf(x, "[%g,%g]", p->a[i*2], p->a[i*2+1]);
   328         -      sqlite3_str_append(x, i==p->nVertex-1 ? "]" : ",", 1);
          331  +      sqlite3_str_appendf(x, "[%!g,%!g],", p->a[i*2], p->a[i*2+1]);
   329    332       }
          333  +    sqlite3_str_appendf(x, "[%!g,%!g]]", p->a[0], p->a[1]);
   330    334       sqlite3_result_text(context, sqlite3_str_finish(x), -1, sqlite3_free);
   331    335       sqlite3_free(p);
   332    336     }
   333    337   }
   334    338   
   335    339   
   336    340   /*