/ 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 Unified Diffs Ignore Whitespace Patch

Changes to ext/misc/geopoly.c.

219
220
221
222
223
224
225
226




227
228
229
230
231
232
233
234
235
236
...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
      }
      if( geopolySkipSpace(&s)==',' ){
        s.z++;
        continue;
      }
      break;
    }
    if( geopolySkipSpace(&s)==']' ){




      int nByte = sizeof(GeoPoly) * (s.nVertex-1)*2*sizeof(GeopolyCoord);
      GeoPoly *pOut = sqlite3_malloc64( nByte );
      int x = 1;
      if( pOut==0 ) goto parse_json_err;
      pOut->nVertex = s.nVertex;
      memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeopolyCoord));
      pOut->hdr[0] = *(unsigned char*)&x;
      pOut->hdr[1] = (s.nVertex>>16)&0xff;
      pOut->hdr[2] = (s.nVertex>>8)&0xff;
      pOut->hdr[3] = s.nVertex&0xff;
................................................................................
  GeoPoly *p = geopolyFuncParam(context, argv[0]);
  if( p ){
    sqlite3 *db = sqlite3_context_db_handle(context);
    sqlite3_str *x = sqlite3_str_new(db);
    int i;
    sqlite3_str_append(x, "[", 1);
    for(i=0; i<p->nVertex; i++){
      sqlite3_str_appendf(x, "[%g,%g]", p->a[i*2], p->a[i*2+1]);
      sqlite3_str_append(x, i==p->nVertex-1 ? "]" : ",", 1);
    }
    sqlite3_result_text(context, sqlite3_str_finish(x), -1, sqlite3_free);
    sqlite3_free(p);
  }
}


/*







|
>
>
>
>
|
|
|







 







|
|
|







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


/*