| | 1300 | |
|---|
| | 1301 | /* -------------------------------------------------------------------- */ |
|---|
| | 1302 | static OGRGeometryH GCIOAPI_CALL _buildOGRGeometry_GCIO ( |
|---|
| | 1303 | GCExportFileMetadata* Meta, |
|---|
| | 1304 | GCSubType* theSubType, |
|---|
| | 1305 | int i, |
|---|
| | 1306 | const char** pszFields, |
|---|
| | 1307 | int nbtp, |
|---|
| | 1308 | GCDim d |
|---|
| | 1309 | ) |
|---|
| | 1310 | { |
|---|
| | 1311 | OGRGeometryH g; |
|---|
| | 1312 | OGRwkbGeometryType gt; |
|---|
| | 1313 | double x, y, z; |
|---|
| | 1314 | int ip, np; |
|---|
| | 1315 | |
|---|
| | 1316 | g= NULL; |
|---|
| | 1317 | x= y= z= 0.0; |
|---|
| | 1318 | switch( GetSubTypeKind_GCIO(theSubType) ) |
|---|
| | 1319 | { |
|---|
| | 1320 | case vPoint_GCIO : |
|---|
| | 1321 | gt= wkbPoint; |
|---|
| | 1322 | break; |
|---|
| | 1323 | case vLine_GCIO : |
|---|
| | 1324 | gt= wkbLineString; |
|---|
| | 1325 | break; |
|---|
| | 1326 | case vPoly_GCIO : |
|---|
| | 1327 | gt= wkbMultiPolygon; |
|---|
| | 1328 | break; |
|---|
| | 1329 | case vText_GCIO : |
|---|
| | 1330 | default : |
|---|
| | 1331 | gt= wkbUnknown; |
|---|
| | 1332 | break; |
|---|
| | 1333 | } |
|---|
| | 1334 | if( !(g= OGR_G_CreateGeometry(gt)) ) |
|---|
| | 1335 | { |
|---|
| | 1336 | return NULL; |
|---|
| | 1337 | } |
|---|
| | 1338 | OGR_G_SetCoordinateDimension(g,d==v3D_GCIO||d==v3DM_GCIO? 3:2); |
|---|
| | 1339 | if( !GetMetaSRS_GCIO(Meta) && GetMetaSysCoord_GCIO(Meta) ) |
|---|
| | 1340 | { |
|---|
| | 1341 | SetMetaSRS_GCIO(Meta, SysCoord2OGRSpatialReference_GCSRS(GetMetaSysCoord_GCIO(Meta))); |
|---|
| | 1342 | OSRReference( GetMetaSRS_GCIO(Meta) ); |
|---|
| | 1343 | } |
|---|
| | 1344 | if( GetMetaSRS_GCIO(Meta) ) |
|---|
| | 1345 | { |
|---|
| | 1346 | OGR_G_AssignSpatialReference(g,GetMetaSRS_GCIO(Meta)); |
|---|
| | 1347 | } |
|---|
| | 1348 | |
|---|
| | 1349 | /* |
|---|
| | 1350 | * General structure : |
|---|
| | 1351 | * X<>Y[<>Z]{<>More Graphics} |
|---|
| | 1352 | */ |
|---|
| | 1353 | |
|---|
| | 1354 | if( gt==wkbPoint ) |
|---|
| | 1355 | { |
|---|
| | 1356 | /* |
|---|
| | 1357 | * More Graphics : |
|---|
| | 1358 | * Angle |
|---|
| | 1359 | * Angle in tenth of degrees (counterclockwise) of the symbol |
|---|
| | 1360 | * displayed to represent the ponctual entity or angle of the text entity |
|---|
| | 1361 | * NOT IMPLEMENTED |
|---|
| | 1362 | */ |
|---|
| | 1363 | x= CPLAtof(pszFields[i]), i++; |
|---|
| | 1364 | y= CPLAtof(pszFields[i]), i++; |
|---|
| | 1365 | if( d==v3D_GCIO || d==v3DM_GCIO ) |
|---|
| | 1366 | { |
|---|
| | 1367 | z= CPLAtof(pszFields[i]), i++; |
|---|
| | 1368 | } |
|---|
| | 1369 | OGR_G_AddPoint(g,x,y,z); |
|---|
| | 1370 | return g; |
|---|
| | 1371 | } |
|---|
| | 1372 | |
|---|
| | 1373 | if( gt==wkbLineString ) |
|---|
| | 1374 | { |
|---|
| | 1375 | /* |
|---|
| | 1376 | * More Graphics : |
|---|
| | 1377 | * XP<>YP[<>ZP]Nr points=k[<>X<>Y[<>Z]]k... |
|---|
| | 1378 | */ |
|---|
| | 1379 | x= CPLAtof(pszFields[i]), i++; |
|---|
| | 1380 | y= CPLAtof(pszFields[i]), i++; |
|---|
| | 1381 | if( d==v3D_GCIO || d==v3DM_GCIO ) |
|---|
| | 1382 | { |
|---|
| | 1383 | z= CPLAtof(pszFields[i]), i++; |
|---|
| | 1384 | } |
|---|
| | 1385 | OGR_G_AddPoint(g,x,y,z); |
|---|
| | 1386 | /* skip XP<>YP[<>ZP] : the last point is in k[<>X<>Y[<>Z]]k */ |
|---|
| | 1387 | i++; |
|---|
| | 1388 | i++; |
|---|
| | 1389 | if( d==v3D_GCIO || d==v3DM_GCIO ) |
|---|
| | 1390 | { |
|---|
| | 1391 | i++; |
|---|
| | 1392 | } |
|---|
| | 1393 | np= atoi(pszFields[i]), i++; |
|---|
| | 1394 | for( ip= 1; ip<=np; ip++ ) |
|---|
| | 1395 | { |
|---|
| | 1396 | x= CPLAtof(pszFields[i]), i++; |
|---|
| | 1397 | y= CPLAtof(pszFields[i]), i++; |
|---|
| | 1398 | if( d==v3D_GCIO || d==v3DM_GCIO ) |
|---|
| | 1399 | { |
|---|
| | 1400 | z= CPLAtof(pszFields[i]), i++; |
|---|
| | 1401 | } |
|---|
| | 1402 | OGR_G_AddPoint(g,x,y,z); |
|---|
| | 1403 | } |
|---|
| | 1404 | return g; |
|---|
| | 1405 | } |
|---|
| | 1406 | |
|---|
| | 1407 | if( gt==wkbMultiPolygon ) |
|---|
| | 1408 | { |
|---|
| | 1409 | /* |
|---|
| | 1410 | * More Graphics : |
|---|
| | 1411 | * {Single Polygon{<>NrPolys=j[<>X<>Y[<>Z]<>Single Polygon]j}} |
|---|
| | 1412 | * with Single Polygon : |
|---|
| | 1413 | * Nr points=k[<>X<>Y[<>Z]]k... |
|---|
| | 1414 | */ |
|---|
| | 1415 | CPLList* Lpo, *e; |
|---|
| | 1416 | OGRGeometryH outer, ring; |
|---|
| | 1417 | int npo, ipo, ilpo; |
|---|
| | 1418 | |
|---|
| | 1419 | |
|---|
| | 1420 | Lpo= NULL; |
|---|
| | 1421 | if( !(outer= OGR_G_CreateGeometry(wkbPolygon)) ) |
|---|
| | 1422 | { |
|---|
| | 1423 | goto onError; |
|---|
| | 1424 | } |
|---|
| | 1425 | OGR_G_SetCoordinateDimension(outer,d==v3D_GCIO||v3DM_GCIO? 3:2); |
|---|
| | 1426 | if( GetMetaSRS_GCIO(Meta) ) |
|---|
| | 1427 | { |
|---|
| | 1428 | OGR_G_AssignSpatialReference(outer,GetMetaSRS_GCIO(Meta)); |
|---|
| | 1429 | } |
|---|
| | 1430 | if( !(ring= OGR_G_CreateGeometry(wkbLinearRing)) ) |
|---|
| | 1431 | { |
|---|
| | 1432 | OGR_G_DestroyGeometry(outer); |
|---|
| | 1433 | goto onError; |
|---|
| | 1434 | } |
|---|
| | 1435 | OGR_G_SetCoordinateDimension(ring,d==v3D_GCIO||v3DM_GCIO? 3:2); |
|---|
| | 1436 | if( GetMetaSRS_GCIO(Meta) ) |
|---|
| | 1437 | { |
|---|
| | 1438 | OGR_G_AssignSpatialReference(ring,GetMetaSRS_GCIO(Meta)); |
|---|
| | 1439 | } |
|---|
| | 1440 | x= CPLAtof(pszFields[i]), i++; |
|---|
| | 1441 | y= CPLAtof(pszFields[i]), i++; |
|---|
| | 1442 | if( d==v3D_GCIO || d==v3DM_GCIO ) |
|---|
| | 1443 | { |
|---|
| | 1444 | z= CPLAtof(pszFields[i]), i++; |
|---|
| | 1445 | } |
|---|
| | 1446 | OGR_G_AddPoint(ring,x,y,z); |
|---|
| | 1447 | np= atoi(pszFields[i]), i++; |
|---|
| | 1448 | for( ip= 1; ip<=np; ip++ ) |
|---|
| | 1449 | { |
|---|
| | 1450 | x= CPLAtof(pszFields[i]), i++; |
|---|
| | 1451 | y= CPLAtof(pszFields[i]), i++; |
|---|
| | 1452 | if( d==v3D_GCIO || d==v3DM_GCIO ) |
|---|
| | 1453 | { |
|---|
| | 1454 | z= CPLAtof(pszFields[i]), i++; |
|---|
| | 1455 | } |
|---|
| | 1456 | OGR_G_AddPoint(ring,x,y,z); |
|---|
| | 1457 | } |
|---|
| | 1458 | OGR_G_AddGeometryDirectly(outer,ring); |
|---|
| | 1459 | if( (Lpo= CPLListAppend(Lpo,outer))==NULL ) |
|---|
| | 1460 | { |
|---|
| | 1461 | CPLError( CE_Failure, CPLE_OutOfMemory, |
|---|
| | 1462 | "failed to add a polygon to subtype '%s.%s'.\n", |
|---|
| | 1463 | GetTypeName_GCIO(GetSubTypeType_GCIO(theSubType)), |
|---|
| | 1464 | GetSubTypeName_GCIO(theSubType) ); |
|---|
| | 1465 | OGR_G_DestroyGeometry(outer); |
|---|
| | 1466 | goto onError; |
|---|
| | 1467 | } |
|---|
| | 1468 | /* additionnal ring : either holes, or islands */ |
|---|
| | 1469 | if( i < nbtp-1 ) |
|---|
| | 1470 | { |
|---|
| | 1471 | npo= atoi(pszFields[i]), i++; |
|---|
| | 1472 | for( ipo= 1; ipo<=npo; ipo++ ) |
|---|
| | 1473 | { |
|---|
| | 1474 | if( !(ring= OGR_G_CreateGeometry(wkbLinearRing)) ) |
|---|
| | 1475 | { |
|---|
| | 1476 | goto onError; |
|---|
| | 1477 | } |
|---|
| | 1478 | OGR_G_SetCoordinateDimension(ring,d==v3D_GCIO||v3DM_GCIO? 3:2); |
|---|
| | 1479 | if( GetMetaSRS_GCIO(Meta) ) |
|---|
| | 1480 | { |
|---|
| | 1481 | OGR_G_AssignSpatialReference(ring,GetMetaSRS_GCIO(Meta)); |
|---|
| | 1482 | } |
|---|
| | 1483 | x= CPLAtof(pszFields[i]), i++; |
|---|
| | 1484 | y= CPLAtof(pszFields[i]), i++; |
|---|
| | 1485 | if( d==v3D_GCIO || d==v3DM_GCIO ) |
|---|
| | 1486 | { |
|---|
| | 1487 | z= CPLAtof(pszFields[i]), i++; |
|---|
| | 1488 | } |
|---|
| | 1489 | OGR_G_AddPoint(ring,x,y,z); |
|---|
| | 1490 | np= atoi(pszFields[i]), i++; |
|---|
| | 1491 | for( ip= 1; ip<=np; ip++ ) |
|---|
| | 1492 | { |
|---|
| | 1493 | x= CPLAtof(pszFields[i]), i++; |
|---|
| | 1494 | y= CPLAtof(pszFields[i]), i++; |
|---|
| | 1495 | if( d==v3D_GCIO || d==v3DM_GCIO ) |
|---|
| | 1496 | { |
|---|
| | 1497 | z= CPLAtof(pszFields[i]), i++; |
|---|
| | 1498 | } |
|---|
| | 1499 | OGR_G_AddPoint(ring,x,y,z); |
|---|
| | 1500 | } |
|---|
| | 1501 | /* is the ring of hole or another polygon ? */ |
|---|
| | 1502 | for( ilpo= 0; ilpo<CPLListCount(Lpo); ilpo++) |
|---|
| | 1503 | { |
|---|
| | 1504 | if( (e= CPLListGet(Lpo,ilpo)) ) |
|---|
| | 1505 | { |
|---|
| | 1506 | if( (outer= (OGRGeometryH)CPLListGetData(e)) ) |
|---|
| | 1507 | { |
|---|
| | 1508 | if( OGR_G_Contains(outer,ring) ) |
|---|
| | 1509 | { |
|---|
| | 1510 | OGR_G_AddGeometryDirectly(outer,ring); |
|---|
| | 1511 | ring= NULL; |
|---|
| | 1512 | break; |
|---|
| | 1513 | } |
|---|
| | 1514 | } |
|---|
| | 1515 | } |
|---|
| | 1516 | } |
|---|
| | 1517 | if( !ring ) |
|---|
| | 1518 | { |
|---|
| | 1519 | /* new polygon */ |
|---|
| | 1520 | if( !(outer= OGR_G_CreateGeometry(wkbPolygon)) ) |
|---|
| | 1521 | { |
|---|
| | 1522 | OGR_G_DestroyGeometry(ring); |
|---|
| | 1523 | goto onError; |
|---|
| | 1524 | } |
|---|
| | 1525 | OGR_G_SetCoordinateDimension(outer,d==v3D_GCIO||v3DM_GCIO? 3:2); |
|---|
| | 1526 | if( GetMetaSRS_GCIO(Meta) ) |
|---|
| | 1527 | { |
|---|
| | 1528 | OGR_G_AssignSpatialReference(outer,GetMetaSRS_GCIO(Meta)); |
|---|
| | 1529 | } |
|---|
| | 1530 | OGR_G_AddGeometryDirectly(outer,ring); |
|---|
| | 1531 | if( (Lpo= CPLListAppend(Lpo,outer))==NULL ) |
|---|
| | 1532 | { |
|---|
| | 1533 | CPLError( CE_Failure, CPLE_OutOfMemory, |
|---|
| | 1534 | "failed to add a polygon to subtype '%s.%s'.\n", |
|---|
| | 1535 | GetTypeName_GCIO(GetSubTypeType_GCIO(theSubType)), |
|---|
| | 1536 | GetSubTypeName_GCIO(theSubType) ); |
|---|
| | 1537 | OGR_G_DestroyGeometry(outer); |
|---|
| | 1538 | goto onError; |
|---|
| | 1539 | } |
|---|
| | 1540 | } |
|---|
| | 1541 | } |
|---|
| | 1542 | } |
|---|
| | 1543 | if( Lpo ) |
|---|
| | 1544 | { |
|---|
| | 1545 | if( (npo= CPLListCount(Lpo))>0 ) |
|---|
| | 1546 | { |
|---|
| | 1547 | for (ipo= 0; ipo<npo; ipo++) |
|---|
| | 1548 | { |
|---|
| | 1549 | if( (e= CPLListGet(Lpo,ipo)) ) |
|---|
| | 1550 | { |
|---|
| | 1551 | if( (outer= (OGRGeometryH)CPLListGetData(e)) ) |
|---|
| | 1552 | { |
|---|
| | 1553 | OGR_G_AddGeometryDirectly(g,outer); |
|---|
| | 1554 | } |
|---|
| | 1555 | } |
|---|
| | 1556 | } |
|---|
| | 1557 | } |
|---|
| | 1558 | CPLListDestroy(Lpo); |
|---|
| | 1559 | } |
|---|
| | 1560 | return g; |
|---|
| | 1561 | |
|---|
| | 1562 | onError: |
|---|
| | 1563 | if( Lpo ) |
|---|
| | 1564 | { |
|---|
| | 1565 | if( (npo= CPLListCount(Lpo))>0 ) |
|---|
| | 1566 | { |
|---|
| | 1567 | for (ipo= 0; ipo<npo; ipo++) |
|---|
| | 1568 | { |
|---|
| | 1569 | if( (e= CPLListGet(Lpo,ipo)) ) |
|---|
| | 1570 | { |
|---|
| | 1571 | if( (outer= (OGRGeometryH)CPLListGetData(e)) ) |
|---|
| | 1572 | { |
|---|
| | 1573 | OGR_G_DestroyGeometry(outer); |
|---|
| | 1574 | } |
|---|
| | 1575 | } |
|---|
| | 1576 | } |
|---|
| | 1577 | } |
|---|
| | 1578 | CPLListDestroy(Lpo); |
|---|
| | 1579 | } |
|---|
| | 1580 | if( g ) OGR_G_DestroyGeometry(g); |
|---|
| | 1581 | } |
|---|
| | 1582 | |
|---|
| | 1583 | return NULL; |
|---|
| | 1584 | }/* _buildOGRGeometry_GCIO */ |
|---|
| | 1585 | |
|---|
| | 1586 | /* -------------------------------------------------------------------- */ |
|---|
| | 1587 | static OGRFeatureH GCIOAPI_CALL _buildOGRFeature_GCIO ( |
|---|
| | 1588 | GCExportFileH* H, |
|---|
| | 1589 | GCSubType** theSubType, |
|---|
| | 1590 | GCDim d |
|---|
| | 1591 | ) |
|---|
| | 1592 | { |
|---|
| | 1593 | GCExportFileMetadata* Meta; |
|---|
| | 1594 | char **pszFields, delim[2], tdst[kItemSize_GCIO]; |
|---|
| | 1595 | int whereClass, whereSubType, i, j, nbf, nbtf; |
|---|
| | 1596 | GCType* theClass; |
|---|
| | 1597 | GCField* theField; |
|---|
| | 1598 | OGRFieldDefnH fld; |
|---|
| | 1599 | OGRFeatureDefnH fd; |
|---|
| | 1600 | OGRFeatureH f; |
|---|
| | 1601 | OGRGeometryH g; |
|---|
| | 1602 | |
|---|
| | 1603 | fd= NULL; |
|---|
| | 1604 | f= NULL; |
|---|
| | 1605 | Meta= GetGCMeta_GCIO(H); |
|---|
| | 1606 | delim[0]= GetMetaDelimiter_GCIO(Meta); |
|---|
| | 1607 | delim[1]= '\0'; |
|---|
| | 1608 | if( d==vUnknown3D_GCIO) d= v2D_GCIO; |
|---|
| | 1609 | /* due to the order of fields, we know how to proceed : */ |
|---|
| | 1610 | /* A.- Line syntax : */ |
|---|
| | 1611 | /* Object internal identifier <delimiter> */ |
|---|
| | 1612 | /* Class <delimiter> */ |
|---|
| | 1613 | /* Subclass <delimiter> */ |
|---|
| | 1614 | /* Name <delimiter> */ |
|---|
| | 1615 | /* NbFields <delimiter> */ |
|---|
| | 1616 | /* User's field <delimiter> [0..N] */ |
|---|
| | 1617 | /* Graphics */ |
|---|
| | 1618 | /* Graphics depends on the Kind of the */ |
|---|
| | 1619 | /* B.- Algorithm : */ |
|---|
| | 1620 | /* 1.- Get Class */ |
|---|
| | 1621 | /* 2.- Get Subclass */ |
|---|
| | 1622 | /* 3.- Find feature in schema */ |
|---|
| | 1623 | /* 4.- Get Kind */ |
|---|
| | 1624 | /* 5.- Get NbFields */ |
|---|
| | 1625 | /* 6.- Get Geometry as 5+NbFields field */ |
|---|
| | 1626 | /* 7.- Parse Geometry and build OGRGeometryH */ |
|---|
| | 1627 | /* 8.- Compute extent and update file extent */ |
|---|
| | 1628 | /* 9.- increment number of features */ |
|---|
| | 1629 | /* FIXME : add index when reading feature to */ |
|---|
| | 1630 | /* allow direct access ! */ |
|---|
| | 1631 | if( !(pszFields= CSLTokenizeStringComplex(GetGCCache_GCIO(H), |
|---|
| | 1632 | delim, |
|---|
| | 1633 | GetMetaQuotedText_GCIO(Meta), |
|---|
| | 1634 | TRUE)) ) |
|---|
| | 1635 | { |
|---|
| | 1636 | CPLError( CE_Failure, CPLE_AppDefined, |
|---|
| | 1637 | "Line %ld, Geoconcept line syntax is incorrect.\n", |
|---|
| | 1638 | GetGCCurrentLinenum_GCIO(H) ); |
|---|
| | 1639 | return NULL; |
|---|
| | 1640 | } |
|---|
| | 1641 | if( (nbtf= CSLCount(pszFields)) <= 5 ) |
|---|
| | 1642 | { |
|---|
| | 1643 | CPLError( CE_Failure, CPLE_AppDefined, |
|---|
| | 1644 | "Line %ld, Missing fields.\n", |
|---|
| | 1645 | GetGCCurrentLinenum_GCIO(H) ); |
|---|
| | 1646 | return NULL; |
|---|
| | 1647 | } |
|---|
| | 1648 | if( (whereClass = _findTypeByName_GCIO(H,pszFields[1]))==-1 ) |
|---|
| | 1649 | { |
|---|
| | 1650 | CPLError( CE_Failure, CPLE_AppDefined, |
|---|
| | 1651 | "Line %ld, Unknown type '%s'.\n", |
|---|
| | 1652 | GetGCCurrentLinenum_GCIO(H), pszFields[1] ); |
|---|
| | 1653 | return NULL; |
|---|
| | 1654 | } |
|---|
| | 1655 | theClass= _getType_GCIO(H,whereClass); |
|---|
| | 1656 | if( *theSubType ) |
|---|
| | 1657 | { |
|---|
| | 1658 | /* reading ... */ |
|---|
| | 1659 | if( !EQUAL(GetTypeName_GCIO(GetSubTypeType_GCIO(*theSubType)),GetTypeName_GCIO(theClass)) ) |
|---|
| | 1660 | { |
|---|
| | 1661 | return NULL; |
|---|
| | 1662 | } |
|---|
| | 1663 | } |
|---|
| | 1664 | if( (whereSubType= _findSubTypeByName_GCIO(theClass,pszFields[2]))==-1 ) |
|---|
| | 1665 | { |
|---|
| | 1666 | CPLError( CE_Failure, CPLE_AppDefined, |
|---|
| | 1667 | "Line %ld, Unknown subtype found '%s' for type '%s'.\n", |
|---|
| | 1668 | GetGCCurrentLinenum_GCIO(H), pszFields[2], pszFields[1] ); |
|---|
| | 1669 | return NULL; |
|---|
| | 1670 | } |
|---|
| | 1671 | if( *theSubType ) |
|---|
| | 1672 | { |
|---|
| | 1673 | if( !EQUAL(GetSubTypeName_GCIO(_getSubType_GCIO(theClass,whereSubType)),GetSubTypeName_GCIO(*theSubType)) ) |
|---|
| | 1674 | { |
|---|
| | 1675 | return NULL; |
|---|
| | 1676 | } |
|---|
| | 1677 | } |
|---|
| | 1678 | else |
|---|
| | 1679 | { |
|---|
| | 1680 | *theSubType= _getSubType_GCIO(theClass,whereSubType); |
|---|
| | 1681 | } |
|---|
| | 1682 | snprintf(tdst, kItemSize_GCIO-1, "%s.%s", GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(*theSubType)); |
|---|
| | 1683 | tdst[kItemSize_GCIO-1]= '\0'; |
|---|
| | 1684 | if( _findFieldByName_GCIO(GetSubTypeFields_GCIO(*theSubType),kName_GCIO)!=-1 ) |
|---|
| | 1685 | { |
|---|
| | 1686 | nbf= 4; |
|---|
| | 1687 | } |
|---|
| | 1688 | else |
|---|
| | 1689 | { |
|---|
| | 1690 | nbf= 3; |
|---|
| | 1691 | } |
|---|
| | 1692 | if( atoi(pszFields[nbf])!=GetSubTypeNbFields_GCIO(*theSubType) ) |
|---|
| | 1693 | { |
|---|
| | 1694 | CPLError( CE_Failure, CPLE_AppDefined, |
|---|
| | 1695 | "Line %ld, Number of user's fields differs with type definition '%s' (%d found, %d expected).\n", |
|---|
| | 1696 | GetGCCurrentLinenum_GCIO(H), tdst, atoi(pszFields[nbf]), GetSubTypeNbFields_GCIO(*theSubType) ); |
|---|
| | 1697 | return NULL; |
|---|
| | 1698 | } |
|---|
| | 1699 | if( !(fd= OGR_FD_Create(tdst)) ) |
|---|
| | 1700 | { |
|---|
| | 1701 | return NULL; |
|---|
| | 1702 | } |
|---|
| | 1703 | OGR_FD_Reference(fd);/* FIXME ? */ |
|---|
| | 1704 | switch( GetSubTypeKind_GCIO(*theSubType) ) |
|---|
| | 1705 | { |
|---|
| | 1706 | case vPoint_GCIO : |
|---|
| | 1707 | OGR_FD_SetGeomType(fd,wkbPoint); |
|---|
| | 1708 | break; |
|---|
| | 1709 | case vLine_GCIO : |
|---|
| | 1710 | OGR_FD_SetGeomType(fd,wkbLineString); |
|---|
| | 1711 | break; |
|---|
| | 1712 | case vPoly_GCIO : |
|---|
| | 1713 | OGR_FD_SetGeomType(fd,wkbMultiPolygon); |
|---|
| | 1714 | break; |
|---|
| | 1715 | case vText_GCIO : |
|---|
| | 1716 | default : |
|---|
| | 1717 | OGR_FD_Dereference(fd); |
|---|
| | 1718 | OGR_FD_Destroy(fd); |
|---|
| | 1719 | CPLError( CE_Failure, CPLE_NotSupported, |
|---|
| | 1720 | "Unknown Geoconcept type for '%s'.\n", |
|---|
| | 1721 | tdst ); |
|---|
| | 1722 | return NULL; |
|---|
| | 1723 | } |
|---|
| | 1724 | if( nbtf < 1 + nbf + GetSubTypeNbFields_GCIO(*theSubType) + 1) |
|---|
| | 1725 | { |
|---|
| | 1726 | OGR_FD_Destroy(fd); |
|---|
| | 1727 | CPLError( CE_Failure, CPLE_AppDefined, |
|---|
| | 1728 | "Line %ld, Missing fields.\n", |
|---|
| | 1729 | GetGCCurrentLinenum_GCIO(H) ); |
|---|
| | 1730 | return NULL; |
|---|
| | 1731 | } |
|---|
| | 1732 | for( i= 1 + nbf; i<1 + nbf + GetSubTypeNbFields_GCIO(*theSubType); i++ ) |
|---|
| | 1733 | { |
|---|
| | 1734 | theField= GetSubTypeField_GCIO(*theSubType,i); |
|---|
| | 1735 | if( !(fld= OGR_Fld_Create(GetFieldName_GCIO(theField),OFTString)) ) /* FIXME */ |
|---|
| | 1736 | { |
|---|
| | 1737 | OGR_FD_Destroy(fd); |
|---|
| | 1738 | return NULL; |
|---|
| | 1739 | } |
|---|
| | 1740 | OGR_FD_AddFieldDefn(fd,fld); |
|---|
| | 1741 | } |
|---|
| | 1742 | if( !(f= OGR_F_Create(fd)) ) |
|---|
| | 1743 | { |
|---|
| | 1744 | OGR_FD_Destroy(fd); |
|---|
| | 1745 | return NULL; |
|---|
| | 1746 | } |
|---|
| | 1747 | OGR_F_SetFID(f, atol(pszFields[0])); /* FID */ |
|---|
| | 1748 | for( i= 1 + nbf, j= 0; i<1 + nbf + GetSubTypeNbFields_GCIO(*theSubType); i++, j++ ) |
|---|
| | 1749 | { |
|---|
| | 1750 | theField= GetSubTypeField_GCIO(*theSubType,i); |
|---|
| | 1751 | if( pszFields[i][0]=='\0' ) |
|---|
| | 1752 | OGR_F_UnsetField(f,j); |
|---|
| | 1753 | else |
|---|
| | 1754 | OGR_F_SetFieldString(f,j,pszFields[i]); |
|---|
| | 1755 | } |
|---|
| | 1756 | if( !(g= _buildOGRGeometry_GCIO(Meta,*theSubType,i,(const char **)pszFields,nbtf,d)) ) |
|---|
| | 1757 | { |
|---|
| | 1758 | OGR_F_Destroy(f); |
|---|
| | 1759 | return NULL; |
|---|
| | 1760 | } |
|---|
| | 1761 | if( OGR_F_SetGeometryDirectly(f,g)!=OGRERR_NONE ) |
|---|
| | 1762 | { |
|---|
| | 1763 | OGR_F_Destroy(f); |
|---|
| | 1764 | return NULL; |
|---|
| | 1765 | } |
|---|
| | 1766 | CSLDestroy(pszFields); |
|---|
| | 1767 | |
|---|
| | 1768 | return f; |
|---|
| | 1769 | }/* _buildOGRFeature_GCIO */ |
|---|
| | 1770 | |
|---|
| | 1771 | /* -------------------------------------------------------------------- */ |
|---|
| | 1772 | static GCExportFileMetadata GCIOAPI_CALL1(*) _completeHeader_GCIO ( |
|---|
| | 1773 | GCExportFileH* H |
|---|
| | 1774 | ) |
|---|
| | 1775 | { |
|---|
| | 1776 | GCExportFileMetadata* Meta; |
|---|
| | 1777 | GCSubType* theSubType; |
|---|
| | 1778 | OGRFeatureH f; |
|---|
| | 1779 | GCDim d; |
|---|
| | 1780 | long coff; |
|---|
| | 1781 | OGREnvelope bbox; |
|---|
| | 1782 | |
|---|
| | 1783 | if( (Meta= GetGCMeta_GCIO(H))==NULL ) |
|---|
| | 1784 | { |
|---|
| | 1785 | return NULL; |
|---|
| | 1786 | } |
|---|
| | 1787 | SetMetaExtent_GCIO(Meta, CreateExtent_GCIO(HUGE_VAL,HUGE_VAL,-HUGE_VAL,-HUGE_VAL)); |
|---|
| | 1788 | bbox.MinX= HUGE_VAL; |
|---|
| | 1789 | bbox.MaxX= -HUGE_VAL; |
|---|
| | 1790 | bbox.MinY= HUGE_VAL; |
|---|
| | 1791 | bbox.MaxY= -HUGE_VAL; |
|---|
| | 1792 | |
|---|
| | 1793 | d= vUnknown3D_GCIO; |
|---|
| | 1794 | theSubType= NULL; |
|---|
| | 1795 | coff= -1L; |
|---|
| | 1796 | while( _get_GCIO(H)!=EOF ) |
|---|
| | 1797 | { |
|---|
| | 1798 | if( GetGCWhatIs_GCIO(H)==vComType_GCIO ) |
|---|
| | 1799 | { |
|---|
| | 1800 | continue; |
|---|
| | 1801 | } |
|---|
| | 1802 | /* analyze the line according to schema : */ |
|---|
| | 1803 | if( GetGCWhatIs_GCIO(H)==vPragma_GCIO ) |
|---|
| | 1804 | { |
|---|
| | 1805 | if( strstr(GetGCCache_GCIO(H),k3DOBJECTMONO_GCIO) ) |
|---|
| | 1806 | { |
|---|
| | 1807 | d= v3DM_GCIO; |
|---|
| | 1808 | coff= GetGCCurrentOffset_GCIO(H); |
|---|
| | 1809 | } |
|---|
| | 1810 | else if( strstr(GetGCCache_GCIO(H),k3DOBJECT_GCIO) ) |
|---|
| | 1811 | { |
|---|
| | 1812 | d= v3D_GCIO; |
|---|
| | 1813 | coff= GetGCCurrentOffset_GCIO(H); |
|---|
| | 1814 | } |
|---|
| | 1815 | else if( strstr(GetGCCache_GCIO(H),k2DOBJECT_GCIO) ) |
|---|
| | 1816 | { |
|---|
| | 1817 | d= v2D_GCIO; |
|---|
| | 1818 | coff= GetGCCurrentOffset_GCIO(H); |
|---|
| | 1819 | } |
|---|
| | 1820 | continue; |
|---|
| | 1821 | } |
|---|
| | 1822 | if( coff==-1L) coff= GetGCCurrentOffset_GCIO(H); |
|---|
| | 1823 | if( !(f= _buildOGRFeature_GCIO(H,&theSubType,d)) ) |
|---|
| | 1824 | { |
|---|
| | 1825 | return NULL; |
|---|
| | 1826 | } |
|---|
| | 1827 | if( GetSubTypeBOF_GCIO(theSubType)==-1L ) |
|---|
| | 1828 | { |
|---|
| | 1829 | SetSubTypeBOF_GCIO(theSubType,coff);/* Begin Of Features for the Class.Subclass */ |
|---|
| | 1830 | SetSubTypeBOFLinenum_GCIO(theSubType, GetGCCurrentLinenum_GCIO(H)); |
|---|
| | 1831 | } |
|---|
| | 1832 | SetSubTypeNbFeatures_GCIO(theSubType, GetSubTypeNbFeatures_GCIO(theSubType)+1L); |
|---|
| | 1833 | SetGCNbObjects_GCIO(H,GetGCNbObjects_GCIO(H)+1L); |
|---|
| | 1834 | OGR_G_GetEnvelope(OGR_F_GetGeometryRef(f),&bbox); |
|---|
| | 1835 | /* update bbox of both feature and file */ |
|---|
| | 1836 | SetExtentULAbscissa_GCIO(GetMetaExtent_GCIO(Meta),bbox.MinX); |
|---|
| | 1837 | SetExtentULOrdinate_GCIO(GetMetaExtent_GCIO(Meta),bbox.MaxY); |
|---|
| | 1838 | SetExtentLRAbscissa_GCIO(GetMetaExtent_GCIO(Meta),bbox.MaxX); |
|---|
| | 1839 | SetExtentLROrdinate_GCIO(GetMetaExtent_GCIO(Meta),bbox.MinY); |
|---|
| | 1840 | if( !GetSubTypeExtent_GCIO(theSubType) ) |
|---|
| | 1841 | { |
|---|
| | 1842 | SetSubTypeExtent_GCIO(theSubType, CreateExtent_GCIO(HUGE_VAL,HUGE_VAL,-HUGE_VAL,-HUGE_VAL)); |
|---|
| | 1843 | } |
|---|
| | 1844 | SetExtentULAbscissa_GCIO(GetSubTypeExtent_GCIO(theSubType),bbox.MinX); |
|---|
| | 1845 | SetExtentULOrdinate_GCIO(GetSubTypeExtent_GCIO(theSubType),bbox.MaxY); |
|---|
| | 1846 | SetExtentLRAbscissa_GCIO(GetSubTypeExtent_GCIO(theSubType),bbox.MaxX); |
|---|
| | 1847 | SetExtentLROrdinate_GCIO(GetSubTypeExtent_GCIO(theSubType),bbox.MinY); |
|---|
| | 1848 | if( d==vUnknown3D_GCIO && GetSubTypeDim_GCIO(theSubType)==vUnknown3D_GCIO ) |
|---|
| | 1849 | { |
|---|
| | 1850 | switch( OGR_G_GetCoordinateDimension(OGR_F_GetGeometryRef(f)) ) |
|---|
| | 1851 | { |
|---|
| | 1852 | case 3 : |
|---|
| | 1853 | SetSubTypeDim_GCIO(theSubType,v3D_GCIO); |
|---|
| | 1854 | break; |
|---|
| | 1855 | case 2 : |
|---|
| | 1856 | default : < |
|---|