?? s57writer.cpp
字號:
poModule->AddField( poFDefn );/* -------------------------------------------------------------------- *//* Create the FFPC field. *//* -------------------------------------------------------------------- */ poFDefn = new DDFFieldDefn(); poFDefn->Create( "FFPC", "Feature record to feature object pointer control field", "", dsc_vector, dtc_mixed_data_type ); poFDefn->AddSubfield( "FFUI", "b11" ); poFDefn->AddSubfield( "FFIX", "b12" ); poFDefn->AddSubfield( "NFPT", "b12" ); poModule->AddField( poFDefn );/* -------------------------------------------------------------------- *//* Create the FFPT field. *//* -------------------------------------------------------------------- */ poFDefn = new DDFFieldDefn(); poFDefn->Create( "FFPT", "Feature record to feature object pointer field", "*", dsc_array, dtc_mixed_data_type ); poFDefn->AddSubfield( "LNAM", "B(64)" ); poFDefn->AddSubfield( "RIND", "b11" ); poFDefn->AddSubfield( "COMT", "A" ); poModule->AddField( poFDefn );/* -------------------------------------------------------------------- *//* Create the FSPC field. *//* -------------------------------------------------------------------- */ poFDefn = new DDFFieldDefn(); poFDefn->Create( "FSPC", "Feature record to spatial record pointer control field", "", dsc_vector, dtc_mixed_data_type ); poFDefn->AddSubfield( "FSUI", "b11" ); poFDefn->AddSubfield( "FSIX", "b12" ); poFDefn->AddSubfield( "NSPT", "b12" ); poModule->AddField( poFDefn );/* -------------------------------------------------------------------- *//* Create the FSPT field. *//* -------------------------------------------------------------------- */ poFDefn = new DDFFieldDefn(); poFDefn->Create( "FSPT", "Feature record to spatial record pointer field", "*", dsc_array, dtc_mixed_data_type ); poFDefn->AddSubfield( "NAME", "B(40)" ); poFDefn->AddSubfield( "ORNT", "b11" ); poFDefn->AddSubfield( "USAG", "b11" ); poFDefn->AddSubfield( "MASK", "b11" ); poModule->AddField( poFDefn );/* -------------------------------------------------------------------- *//* Create file. *//* -------------------------------------------------------------------- */ if( !poModule->Create( pszFilename ) ) { delete poModule; poModule = NULL; return FALSE; } return TRUE;}/************************************************************************//* WriteDSID() *//************************************************************************/int S57Writer::WriteDSID( const char *pszDSNM, const char *pszISDT, const char *pszSTED, int nAGEN, const char *pszCOMT ){/* -------------------------------------------------------------------- *//* Default values. *//* -------------------------------------------------------------------- */ if( pszDSNM == NULL ) pszDSNM = ""; if( pszISDT == NULL ) pszISDT = "20030801"; if( pszSTED == NULL ) pszSTED = "03.1"; if( pszCOMT == NULL ) pszCOMT = "";/* -------------------------------------------------------------------- *//* Add the DSID field. *//* -------------------------------------------------------------------- */ DDFRecord *poRec = MakeRecord(); DDFField *poField; poField = poRec->AddField( poModule->FindFieldDefn( "DSID" ) ); poRec->SetIntSubfield ( "DSID", 0, "RCNM", 0, 10 ); poRec->SetIntSubfield ( "DSID", 0, "RCID", 0, 1 ); poRec->SetIntSubfield ( "DSID", 0, "EXPP", 0, 1 ); poRec->SetIntSubfield ( "DSID", 0, "INTU", 0, 4 ); poRec->SetStringSubfield( "DSID", 0, "DSNM", 0, pszDSNM ); poRec->SetStringSubfield( "DSID", 0, "EDTN", 0, "2" ); poRec->SetStringSubfield( "DSID", 0, "UPDN", 0, "0" ); poRec->SetStringSubfield( "DSID", 0, "UADT", 0, pszISDT ); poRec->SetStringSubfield( "DSID", 0, "ISDT", 0, pszISDT ); poRec->SetStringSubfield( "DSID", 0, "STED", 0, pszSTED ); poRec->SetIntSubfield ( "DSID", 0, "PRSP", 0, 1 ); poRec->SetStringSubfield( "DSID", 0, "PSDN", 0, "" ); poRec->SetStringSubfield( "DSID", 0, "PRED", 0, "2.0" ); poRec->SetIntSubfield ( "DSID", 0, "PROF", 0, 1 ); poRec->SetIntSubfield ( "DSID", 0, "AGEN", 0, nAGEN ); poRec->SetStringSubfield( "DSID", 0, "COMT", 0, pszCOMT );/* -------------------------------------------------------------------- *//* Add the DSSI record. Eventually we will need to return and *//* correct these when we are finished writing. *//* -------------------------------------------------------------------- */ poField = poRec->AddField( poModule->FindFieldDefn( "DSSI" ) ); poRec->SetIntSubfield ( "DSSI", 0, "DSTR", 0, 2 ); poRec->SetIntSubfield ( "DSSI", 0, "AALL", 0, 1 ); poRec->SetIntSubfield ( "DSSI", 0, "NALL", 0, 1 ); poRec->SetIntSubfield ( "DSSI", 0, "NOMR", 0, 0 ); poRec->SetIntSubfield ( "DSSI", 0, "NOCR", 0, 0 ); poRec->SetIntSubfield ( "DSSI", 0, "NOGR", 0, 3 ); poRec->SetIntSubfield ( "DSSI", 0, "NOLR", 0, 0 ); poRec->SetIntSubfield ( "DSSI", 0, "NOIN", 0, 3 ); poRec->SetIntSubfield ( "DSSI", 0, "NOCN", 0, 0 ); poRec->SetIntSubfield ( "DSSI", 0, "NOED", 0, 0 ); poRec->SetIntSubfield ( "DSSI", 0, "NOFA", 0, 0 );/* -------------------------------------------------------------------- *//* Write out the record. *//* -------------------------------------------------------------------- */ poRec->Write(); delete poRec; return TRUE;}/************************************************************************//* WriteDSPM() *//************************************************************************/int S57Writer::WriteDSPM( int nScale ){ if( nScale == 0 ) nScale = 52000;/* -------------------------------------------------------------------- *//* Add the DSID field. *//* -------------------------------------------------------------------- */ DDFRecord *poRec = MakeRecord(); DDFField *poField; poField = poRec->AddField( poModule->FindFieldDefn( "DSPM" ) ); poRec->SetIntSubfield ( "DSPM", 0, "RCNM", 0, 20 ); poRec->SetIntSubfield ( "DSPM", 0, "RCID", 0, 1 ); poRec->SetIntSubfield ( "DSPM", 0, "HDAT", 0, 2 ); poRec->SetIntSubfield ( "DSPM", 0, "VDAT", 0, 17 ); poRec->SetIntSubfield ( "DSPM", 0, "SDAT", 0, 23 ); poRec->SetIntSubfield ( "DSPM", 0, "CSCL", 0, nScale ); poRec->SetIntSubfield ( "DSPM", 0, "DUNI", 0, 1 ); poRec->SetIntSubfield ( "DSPM", 0, "HUNI", 0, 1 ); poRec->SetIntSubfield ( "DSPM", 0, "PUNI", 0, 1 ); poRec->SetIntSubfield ( "DSPM", 0, "COUN", 0, 1 ); poRec->SetIntSubfield ( "DSPM", 0, "COMF", 0, nCOMF ); poRec->SetIntSubfield ( "DSPM", 0, "SOMF", 0, nSOMF );/* -------------------------------------------------------------------- *//* Write out the record. *//* -------------------------------------------------------------------- */ poRec->Write(); delete poRec; return TRUE;}/************************************************************************//* MakeRecord() *//* *//* Create a new empty record, and append a 0001 field with a *//* properly set record index in it. *//************************************************************************/DDFRecord *S57Writer::MakeRecord(){ DDFRecord *poRec = new DDFRecord( poModule ); DDFField *poField; unsigned char abyData[3]; abyData[0] = nNext0001Index % 256; abyData[1] = nNext0001Index / 256; abyData[2] = DDF_FIELD_TERMINATOR; poField = poRec->AddField( poModule->FindFieldDefn( "0001" ) ); poRec->SetFieldRaw( poField, 0, (const char *) abyData, 3 ); nNext0001Index++; return poRec;}/************************************************************************//* WriteGeometry() *//************************************************************************/int S57Writer::WriteGeometry( DDFRecord *poRec, int nVertCount, double *padfX, double *padfY, double *padfZ ){ const char *pszFieldName = "SG2D"; DDFField *poField; int nRawDataSize, i, nSuccess; unsigned char *pabyRawData; if( padfZ != NULL ) pszFieldName = "SG3D"; poField = poRec->AddField( poModule->FindFieldDefn( pszFieldName ) ); if( padfZ ) nRawDataSize = 12 * nVertCount + 1; else nRawDataSize = 8 * nVertCount + 1; pabyRawData = (unsigned char *) CPLMalloc(nRawDataSize); pabyRawData[nRawDataSize-1] = DDF_UNIT_TERMINATOR; for( i = 0; i < nVertCount; i++ ) { GInt32 nXCOO, nYCOO, nVE3D; nXCOO = CPL_LSBWORD32((GInt32) floor(padfX[i] * nCOMF + 0.5)); nYCOO = CPL_LSBWORD32((GInt32) floor(padfY[i] * nCOMF + 0.5)); if( padfZ == NULL ) { memcpy( pabyRawData + i * 8, &nYCOO, 4 ); memcpy( pabyRawData + i * 8 + 4, &nXCOO, 4 ); } else { nVE3D = CPL_LSBWORD32((GInt32) floor( padfZ[i] * nSOMF + 0.5 )); memcpy( pabyRawData + i * 12, &nYCOO, 4 ); memcpy( pabyRawData + i * 12 + 4, &nXCOO, 4 ); memcpy( pabyRawData + i * 12 + 8, &nVE3D, 4 ); } } nSuccess = poRec->SetFieldRaw( poField, 0, (const char *) pabyRawData, nRawDataSize ); CPLFree( pabyRawData ); return nSuccess;}/************************************************************************//* WritePrimitive() *//************************************************************************/int S57Writer::WritePrimitive( OGRFeature *poFeature ){ DDFRecord *poRec = MakeRecord(); DDFField *poField; OGRGeometry *poGeom = poFeature->GetGeometryRef();/* -------------------------------------------------------------------- *//* Add the VRID field. *//* -------------------------------------------------------------------- */ poField = poRec->AddField( poModule->FindFieldDefn( "VRID" ) ); poRec->SetIntSubfield ( "VRID", 0, "RCNM", 0, poFeature->GetFieldAsInteger( "RCNM") ); poRec->SetIntSubfield ( "VRID", 0, "RCID", 0, poFeature->GetFieldAsInteger( "RCID") ); poRec->SetIntSubfield ( "VRID", 0, "RVER", 0, 1 ); poRec->SetIntSubfield ( "VRID", 0, "RUIN", 0, 1 );/* -------------------------------------------------------------------- *//* Handle simple point. *//* -------------------------------------------------------------------- */ if( poGeom != NULL && wkbFlatten(poGeom->getGeometryType()) == wkbPoint ) { double dfX, dfY, dfZ; OGRPoint *poPoint = (OGRPoint *) poGeom; CPLAssert( poFeature->GetFieldAsInteger( "RCNM") == RCNM_VI || poFeature->GetFieldAsInteger( "RCNM") == RCNM_VC ); dfX = poPoint->getX(); dfY = poPoint->getY(); dfZ = poPoint->getZ(); if( dfZ == 0.0 ) WriteGeometry( poRec, 1, &dfX, &dfY, NULL ); else WriteGeometry( poRec, 1, &dfX, &dfY, &dfZ ); }/* -------------------------------------------------------------------- *//* For multipoints we assuming SOUNDG, and write out as SG3D. *//* -------------------------------------------------------------------- */ else if( poGeom != NULL && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPoint ) { OGRMultiPoint *poMP = (OGRMultiPoint *) poGeom; int i, nVCount = poMP->getNumGeometries(); double *padfX, *padfY, *padfZ; CPLAssert( poFeature->GetFieldAsInteger( "RCNM") == RCNM_VI || poFeature->GetFieldAsInteger( "RCNM") == RCNM_VC ); padfX = (double *) CPLMalloc(sizeof(double) * nVCount); padfY = (double *) CPLMalloc(sizeof(double) * nVCount); padfZ = (double *) CPLMalloc(sizeof(double) * nVCount); for( i = 0; i < nVCount; i++ ) { OGRPoint *poPoint = (OGRPoint *) poMP->getGeometryRef( i ); padfX[i] = poPoint->getX(); padfY[i] = poPoint->getY(); padfZ[i] = poPoint->getZ(); } WriteGeometry( poRec, nVCount, padfX, padfY, padfZ ); CPLFree( padfX ); CPLFree( padfY ); CPLFree( padfZ ); }/* -------------------------------------------------------------------- *//* Handle LINESTRINGs (edge) geometry. *//* -------------------------------------------------------------------- */ else if( poGeom != NULL && wkbFlatten(poGeom->getGeometryType()) == wkbLineString ) { OGRLineString *poLS = (OGRLineString *) poGeom; int i, nVCount = poLS->getNumPoints();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -