//--------------------------------------------------------- bool CPointCloud_From_Text_File::On_Execute(void) { CSG_String fileName; int iField, iType; CSG_String Name, Types, s; CSG_PointCloud *pPoints; CSG_Parameters P; CSG_Parameter *pNode; int xField, yField, zField, nAttribs; bool bSkipHeader; char fieldSep; std::vector<int> vCol; std::ifstream tabStream; std::string tabLine; double lines; long cntPt, cntInvalid; double x, y, z; //----------------------------------------------------- fileName = Parameters("FILE") ->asString(); xField = Parameters("XFIELD") ->asInt() - 1; yField = Parameters("YFIELD") ->asInt() - 1; zField = Parameters("ZFIELD") ->asInt() - 1; bSkipHeader = Parameters("SKIP_HEADER") ->asBool(); switch (Parameters("FIELDSEP")->asInt()) { default: case 0: fieldSep = '\t'; break; case 1: fieldSep = ' '; break; case 2: fieldSep = ','; break; } pPoints = SG_Create_PointCloud(); pPoints->Create(); pPoints->Set_Name(SG_File_Get_Name(fileName, false)); Parameters("POINTS")->Set_Value(pPoints); DataObject_Add(pPoints); //----------------------------------------------------- if (SG_UI_Get_Window_Main()) { nAttribs = Parameters("ATTRIBS") ->asInt(); Types.Printf(SG_T("%s|%s|%s|%s|%s|"), _TL("1 byte integer"), _TL("2 byte integer"), _TL("4 byte integer"), _TL("4 byte floating point"), _TL("8 byte floating point") ); P.Set_Name(_TL("Attribute Field Properties")); for(iField=1; iField<=nAttribs; iField++) { s.Printf(SG_T("NODE_%03d") , iField); pNode = P.Add_Node(NULL, s, CSG_String::Format(SG_T("%d. %s"), iField, _TL("Field")), _TL("")); s.Printf(SG_T("FIELD_%03d"), iField); P.Add_String(pNode, s, _TL("Name"), _TL(""), s); s.Printf(SG_T("COLUMN_%03d"), iField); P.Add_Value(pNode, s, _TL("Attribute is Column ..."), _TL(""), PARAMETER_TYPE_Int, iField+3, 1, true); s.Printf(SG_T("TYPE_%03d") , iField); P.Add_Choice(pNode, s, _TL("Type"), _TL(""), Types, 3); } //----------------------------------------------------- if( nAttribs > 0 ) { if( Dlg_Parameters(&P, _TL("Field Properties")) ) { for(iField=0; iField<nAttribs; iField++) { Name = P(CSG_String::Format(SG_T("FIELD_%03d" ), iField + 1).c_str())->asString(); iType = P(CSG_String::Format(SG_T("TYPE_%03d" ), iField + 1).c_str())->asInt(); vCol.push_back(P(CSG_String::Format(SG_T("COLUMN_%03d"), iField + 1).c_str())->asInt() - 1); pPoints->Add_Field(Name, Get_Data_Type(iType)); } } else return( false ); } } else // CMD { CSG_String sFields, sNames, sTypes; CSG_String token; int iValue; std::vector<int> vTypes; sFields = Parameters("FIELDS")->asString(); sNames = Parameters("FIELDNAMES")->asString(); sTypes = Parameters("FIELDTYPES")->asString(); CSG_String_Tokenizer tkz_fields(sFields, ";", SG_TOKEN_STRTOK); while( tkz_fields.Has_More_Tokens() ) { token = tkz_fields.Get_Next_Token(); if( token.Length() == 0 ) break; if( !token.asInt(iValue) ) { SG_UI_Msg_Add_Error(_TL("Error parsing attribute fields: can't convert to number")); return( false ); } iValue -= 1; if( iValue < 1) { SG_UI_Msg_Add_Error(_TL("Error parsing attribute fields: field index out of range")); return( false ); } else vCol.push_back(iValue); } CSG_String_Tokenizer tkz_datatypes(sTypes, ";", SG_TOKEN_STRTOK); while( tkz_datatypes.Has_More_Tokens() ) { token = tkz_datatypes.Get_Next_Token(); if( token.Length() == 0 ) break; if( !token.asInt(iValue) ) { SG_UI_Msg_Add_Error(_TL("Error parsing field type: can't convert to number")); return( false ); } vTypes.push_back(iValue); } CSG_String_Tokenizer tkz_datanames(sNames, ";", SG_TOKEN_STRTOK); int iter = 0; while( tkz_datanames.Has_More_Tokens() ) { token = tkz_datanames.Get_Next_Token(); if( token.Length() == 0 ) break; pPoints->Add_Field(token, Get_Data_Type(vTypes.at(iter))); iter++; } if( vCol.size() != vTypes.size() || (int)vCol.size() != iter ) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Number of arguments for attribute fields (%d), names (%d) and types (%d) do not match!"), vCol.size(), iter, vTypes.size())); return( false ); } } // open input stream //--------------------------------------------------------- tabStream.open(fileName.b_str(), std::ifstream::in); if( !tabStream ) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unable to open input file!"))); return (false); } tabStream.seekg(0, std::ios::end); // get length of file lines = (double)tabStream.tellg(); tabStream.seekg(0, std::ios::beg); std::getline(tabStream, tabLine); // as a workaround we assume the number of lines from the length of the first line lines = lines / (double)tabStream.tellg(); if( !bSkipHeader ) { tabStream.clear(); // let's forget we may have reached the EOF tabStream.seekg(0, std::ios::beg); // and rewind to the beginning } // import //--------------------------------------------------------- cntPt = cntInvalid = 0; SG_UI_Process_Set_Text(CSG_String::Format(_TL("Importing data ..."))); while( std::getline(tabStream, tabLine) ) { std::istringstream stream(tabLine); std::vector<std::string> tabCols; std::string tabEntry; if( cntPt%10000 == 0 ) { SG_UI_Process_Set_Progress((double)cntPt, lines); } cntPt++; while( std::getline(stream, tabEntry, fieldSep) ) // read every column in this line and fill vector { if (tabEntry.length() == 0) continue; tabCols.push_back(tabEntry); } if ((int)tabCols.size() < (vCol.size() + 3) ) { SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: Skipping misformatted line: %d!"), cntPt), true); cntInvalid++; continue; } //parse line tokens std::vector<double> fieldValues; fieldValues.resize(vCol.size()); x = strtod(tabCols[xField].c_str(), NULL); y = strtod(tabCols[yField].c_str(), NULL); z = strtod(tabCols[zField].c_str(), NULL); for( int i=0; i<(int)vCol.size(); i++ ) { fieldValues[i] = strtod(tabCols.at(vCol.at(i)).c_str(), NULL); } pPoints->Add_Point(x, y, z); for( int i=0; i<(int)vCol.size(); i++ ) { pPoints->Set_Attribute(i, fieldValues[i]); } } // finalize //--------------------------------------------------------- tabStream.close(); CSG_Parameters sParms; DataObject_Get_Parameters(pPoints, sParms); if (sParms("METRIC_ATTRIB") && sParms("COLORS_TYPE") && sParms("METRIC_COLORS") && sParms("METRIC_ZRANGE") && sParms("DISPLAY_VALUE_AGGREGATE")) { sParms("DISPLAY_VALUE_AGGREGATE")->Set_Value(3); // highest z sParms("COLORS_TYPE")->Set_Value(2); // graduated color sParms("METRIC_COLORS")->asColors()->Set_Count(255); // number of colors sParms("METRIC_ATTRIB")->Set_Value(2); // z attrib sParms("METRIC_ZRANGE")->asRange()->Set_Range(pPoints->Get_Minimum(2),pPoints->Get_Maximum(2)); DataObject_Set_Parameters(pPoints, sParms); DataObject_Update(pPoints); } if (cntInvalid > 0) SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %d %s"), _TL("WARNING"), cntInvalid, _TL("invalid points have been skipped")), true); SG_UI_Msg_Add(CSG_String::Format(SG_T("%d %s"), (cntPt-cntInvalid), _TL("points have been imported with success")), true); return( true ); }
//--------------------------------------------------------- bool CSurfer_Export::On_Execute(void) { const char ID_BINARY[] = "DSBB"; FILE *Stream; CSG_Grid *pGrid = Parameters("GRID")->asGrid(); CSG_String File = Parameters("FILE")->asString(); bool bNoData = Parameters("NODATA")->asBool(); switch( Parameters("FORMAT")->asInt() ) { //----------------------------------------------------- case 0: // Surfer 6 - Binary... if( (Stream = fopen(File.b_str(), "wb")) != NULL ) { short sValue; double dValue; fwrite(ID_BINARY, 4, sizeof(char), Stream); sValue = (short)pGrid->Get_NX (); fwrite(&sValue, 1, sizeof(short ), Stream); sValue = (short)pGrid->Get_NY (); fwrite(&sValue, 1, sizeof(short ), Stream); dValue = pGrid->Get_XMin(); fwrite(&dValue, 1, sizeof(double), Stream); dValue = pGrid->Get_XMax(); fwrite(&dValue, 1, sizeof(double), Stream); dValue = pGrid->Get_YMin(); fwrite(&dValue, 1, sizeof(double), Stream); dValue = pGrid->Get_YMax(); fwrite(&dValue, 1, sizeof(double), Stream); dValue = pGrid->Get_Min (); fwrite(&dValue, 1, sizeof(double), Stream); dValue = pGrid->Get_Max (); fwrite(&dValue, 1, sizeof(double), Stream); //--------------------------------------------- float *fLine = (float *)SG_Malloc(pGrid->Get_NX() * sizeof(float)); for(int y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++) { for(int x=0; x<pGrid->Get_NX(); x++) { fLine[x] = bNoData && pGrid->is_NoData(x, y) ? NODATAVALUE : pGrid->asFloat(x, y); } fwrite(fLine, pGrid->Get_NX(), sizeof(float), Stream); } SG_Free(fLine); fclose(Stream); return( true ); } break; //----------------------------------------------------- case 1: // Surfer - ASCII... if( (Stream = fopen(File.b_str(), "w")) != NULL ) { fprintf(Stream, "DSAA\n"); fprintf(Stream, "%d %d\n", pGrid->Get_NX (), pGrid->Get_NY ()); fprintf(Stream, "%f %f\n", pGrid->Get_XMin(), pGrid->Get_XMax()); fprintf(Stream, "%f %f\n", pGrid->Get_YMin(), pGrid->Get_YMax()); fprintf(Stream, "%f %f\n", pGrid->Get_Min (), pGrid->Get_Max ()); //--------------------------------------------- for(int y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++) { for(int x=0; x<pGrid->Get_NX(); x++) { fprintf(Stream, "%f ", bNoData && pGrid->is_NoData(x, y) ? NODATAVALUE : pGrid->asFloat(x, y)); } fprintf(Stream, "\n"); } fclose(Stream); return( true ); } break; } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- bool CWASP_MAP_Export::On_Execute(void) { int zField; FILE *Stream; CSG_String fName; CSG_Shape *pLine; CSG_Shapes *pLines; //----------------------------------------------------- pLines = Parameters("SHAPES") ->asShapes(); zField = Parameters("ELEVATION") ->asInt(); fName = Parameters("FILE") ->asString(); //----------------------------------------------------- if( pLines && pLines->is_Valid() && (Stream = fopen(fName.b_str(), "w")) != NULL ) { // 1) Text string identifying the terrain map: + ... fprintf(Stream, "+ %s\n", pLines->Get_Name()); // 2) Fixed point #1 in user and metric [m] coordinates: // X1(user) Y1(user) X1(metric) Y1(metric) fprintf(Stream, "%f %f %f %f\n", 0.0, 0.0, 0.0, 0.0); // 3) Fixed point #2 in user and metric [m] coordinates: // X2(user) Y2(user) X2(metric) Y2(metric) fprintf(Stream, "%f %f %f %f\n", 1.0, 1.0, 1.0, 1.0); // 4) Scaling factor and offset for height scale (Z): // Zmetric = {scaling factor}(Zuser + {offset}) fprintf(Stream, "%f %f\n", 1.0, 0.0); for(int iLine=0; iLine<pLines->Get_Count() && Set_Progress(iLine, pLines->Get_Count()); iLine++) { pLine = pLines->Get_Shape(iLine); for(int iPart=0; iPart<pLine->Get_Part_Count(); iPart++) { if( pLine->Get_Point_Count(iPart) > 1 ) { // 5a) Height contour: elevation (Z) and number of points (n) in line: // Z n fprintf(Stream, "%f %d\n", pLine->asDouble(zField), pLine->Get_Point_Count(iPart)); // 5b) Roughness change line: // roughness lengths to the left (z0l) and right (z0r) side of the line, // respectively, and number of points: // z0l z0r n // 5c) Roughness and contour line: // roughness lengths to the left and right of the line, // respectively, elevation and number of points: // z0l z0r Z n // 6–) Cartesian coordinates (X, Y) of line described in 5a, 5b or 5c: // X1 Y1 [... Xn Yn] // Xn+1 Yn+1 // ... where [] embrace optional numbers and n is > 0 for(int iPoint=0; iPoint<pLine->Get_Point_Count(iPart); iPoint++) { TSG_Point p = pLine->Get_Point(iPoint, iPart); fprintf(Stream, "%f\t%f\n", p.x, p.y); } } } } fclose(Stream); return( true ); } return( false ); }
size_t CSG_File::Write(CSG_String &Buffer) const { return( Write((void *)Buffer.b_str(), sizeof(char), strlen(Buffer.b_str())) ); }
//--------------------------------------------------------- bool CSurfer_Import::On_Execute(void) { //----------------------------------------------------- CSG_String File = Parameters("FILE")->asString(); FILE *Stream = fopen(File.b_str(), "rb"); if( !Stream ) { Error_Set(_TL("failed to open file")); return( false ); } CSG_Grid *pGrid = NULL; char Id[4]; fread(Id, 1, 4 * sizeof(char), Stream); //----------------------------------------------------- if( !strncmp(Id, "DSRB", 4) ) // Surfer 7: Binary... { long lValue, nx, ny; double dValue, dx, dy, xmin, ymin; fread(&lValue, 1, sizeof(long), Stream); // SectionSize... fread(&lValue, 1, sizeof(long), Stream); // Version fread(&lValue, 1, sizeof(long), Stream); if( lValue == 0x44495247 ) // Grid-Header... { fread(&lValue, 1, sizeof(long ), Stream); // SectionSize... fread(&ny , 1, sizeof(long ), Stream); fread(&nx , 1, sizeof(long ), Stream); fread(&xmin , 1, sizeof(double), Stream); fread(&ymin , 1, sizeof(double), Stream); fread(&dx , 1, sizeof(double), Stream); fread(&dy , 1, sizeof(double), Stream); fread(&dValue, 1, sizeof(double), Stream); fread(&dValue, 1, sizeof(double), Stream); fread(&dValue, 1, sizeof(double), Stream); // Rotation (unused)... fread(&dValue, 1, sizeof(double), Stream); // Blank Value... fread(&lValue, 1, sizeof(long ), Stream); // ???... if( lValue == 0x41544144 ) // Load Binary Double... { fread(&lValue, 1, sizeof(long), Stream); // SectionSize... //----------------------------------------- if( !feof(Stream) && (pGrid = SG_Create_Grid(SG_DATATYPE_Double, nx, ny, dx, xmin, ymin)) != NULL ) { double *Line = (double *)SG_Malloc(pGrid->Get_NX() * sizeof(double)); for(int y=0; y<pGrid->Get_NY() && !feof(Stream) && Set_Progress(y, pGrid->Get_NY()); y++) { fread(Line, pGrid->Get_NX(), sizeof(double), Stream); for(int x=0; x<pGrid->Get_NX(); x++) { pGrid->Set_Value(x, y, Line[x]); } } SG_Free(Line); } } } } //----------------------------------------------------- else if( !strncmp(Id, "DSBB", 4) ) // Surfer 6: Binary... { short nx, ny; double dValue, dx, dy, xmin, ymin; fread(&nx , 1, sizeof(short ), Stream); fread(&ny , 1, sizeof(short ), Stream); fread(&xmin , 1, sizeof(double), Stream); fread(&dx , 1, sizeof(double), Stream); dx = (dx - xmin) / (nx - 1.0); // XMax fread(&ymin , 1, sizeof(double), Stream); fread(&dy , 1, sizeof(double), Stream); dy = (dy - ymin) / (ny - 1.0); // YMax... fread(&dValue, 1, sizeof(double), Stream); // ZMin... fread(&dValue, 1, sizeof(double), Stream); // ZMax... //------------------------------------------------- if( !feof(Stream) && (pGrid = SG_Create_Grid(SG_DATATYPE_Float, nx, ny, dx, xmin, ymin)) != NULL ) { float *Line = (float *)SG_Malloc(pGrid->Get_NX() * sizeof(float)); for(int y=0; y<pGrid->Get_NY() && !feof(Stream) && Set_Progress(y, pGrid->Get_NY()); y++) { fread(Line, pGrid->Get_NX(), sizeof(float), Stream); for(int x=0; x<pGrid->Get_NX(); x++) { pGrid->Set_Value(x, y, Line[x]); } } SG_Free(Line); } } //----------------------------------------------------- else if( !strncmp(Id, "DSAA", 4) ) // Surfer 6: ASCII... { int nx, ny; double dx, dy, xmin, ymin, dValue; fscanf(Stream, "%d %d" , &nx , &ny ); fscanf(Stream, "%lf %lf", &xmin , &dx ); dx = (dx - xmin) / (nx - 1.0); fscanf(Stream, "%lf %lf", &ymin , &dy ); dy = (dy - ymin) / (ny - 1.0); fscanf(Stream, "%lf %lf", &dValue, &dValue); //------------------------------------------------- if( !feof(Stream) && (pGrid = SG_Create_Grid(SG_DATATYPE_Float, nx, ny, dx, xmin, ymin)) != NULL ) { for(int y=0; y<pGrid->Get_NY() && !feof(Stream) && Set_Progress(y, pGrid->Get_NY()); y++) { for(int x=0; x<pGrid->Get_NX(); x++) { fscanf(Stream, "%lf", &dValue); pGrid->Set_Value(x, y, dValue); } } } } //----------------------------------------------------- fclose(Stream); if( pGrid ) { pGrid->Set_Name(SG_File_Get_Name(File, false)); pGrid->Set_NoData_Value(Parameters("NODATA")->asInt() == 0 ? NODATAVALUE : Parameters("NODATA_VAL")->asDouble()); Parameters("GRID")->Set_Value(pGrid); return( true ); } return( false ); }
bool CGPX2SHP::On_Execute(void) { CSG_String sCmd; CSG_String sFile = Parameters("FILE")->asString(); CSG_String sBasePath = Parameters("BASEPATH")->asString(); CSG_String sShapefile; bool bWaypoints = Parameters("WAYPOINTS")->asBool(); bool bTrackpoints = Parameters("TRACKPOINTS")->asBool(); bool bRoutes = Parameters("ROUTES")->asBool(); bool bAdd = Parameters("ADD")->asBool(); CSG_Shapes *pShapes; sCmd = sBasePath + SG_T("\\gpx2shp "); if (bWaypoints) { sCmd += SG_T("-w "); }//if if (bTrackpoints) { sCmd += SG_T("-t "); }//if if (bRoutes) { sCmd += SG_T("-r "); }//if sCmd += sFile; system(sCmd.b_str()); if( bAdd ) { CSG_String sDir(SG_File_Get_Path(sFile)), sName(SG_File_Get_Name(sFile, false)); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_wpt"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_trk"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_rte"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); }//if return true; }//method
bool Ckff_synthesis::On_Execute(void) { CSG_Grid *poutgrid; int numlat = 0; int numlong = 0; int maxdegree = 0; int mindegree = 0; int rc = 0; double inc = 0.0; double lat_start = 0.0; double end_lat = 0.0; double long_start = 0.0; double end_long = 0.0; CSG_String fileName; double **c_lm; double **s_lm; double **gitter; char *error_liste = "nix"; //poutgrid = Parameters ("OUTPUT GRID")->asGrid (); fileName = Parameters("FILE")->asString(); inc = Parameters ("INC")->asDouble (); mindegree = Parameters ("MINDEGREE")->asInt (); maxdegree = Parameters ("MAXDEGREE")->asInt (); lat_start = Parameters ("LAT_START")->asDouble (); end_lat = Parameters ("END_LAT")->asDouble (); long_start = Parameters ("LONG_START")->asDouble (); end_long = Parameters ("END_LONG")->asDouble (); numlat = static_cast <int> (floor ((end_lat - lat_start) / inc) + 1); numlong = static_cast <int> (floor ((end_long - long_start) / inc) + 1); gitter = (double **) matrix_all_alloc (numlat, numlong, 'D', 0); read_coefficients (fileName.b_str(), mindegree, maxdegree, &c_lm, &s_lm); rc = kff_synthese_regel_gitter_m (inc, lat_start, end_lat, long_start, end_long, numlat, numlong, 'A', mindegree, maxdegree, c_lm, s_lm, gitter, &error_liste); poutgrid = SG_Create_Grid(SG_DATATYPE_Double, numlong, numlat, inc, long_start, lat_start); poutgrid ->Set_Name(_TL("Synthesized Grid")); for (int y = 0; y < numlat; y++) { #pragma omp parallel for for (int x = 0; x < numlong; x++) { poutgrid->Set_Value(x,y, gitter[y][x]); } } Parameters("OUTPUT_GRID")->Set_Value(poutgrid); matrix_all_free ((void **) gitter); matrix_all_free ((void **) c_lm); matrix_all_free ((void **) s_lm); return( true ); }
//--------------------------------------------------------- bool CSurfer_Import::On_Execute(void) { int x, y, NX, NY; short sValue; long lValue; float *fLine; double *dLine, dValue, DX, DY, xMin, yMin; FILE *Stream; CSG_String fName; CSG_Grid *pGrid; //----------------------------------------------------- pGrid = NULL; fName = Parameters("FILE")->asString(); //----------------------------------------------------- if( fName.Length() > 0 && (Stream = fopen(fName.b_str(), "rb")) != NULL ) { fread(&lValue, 1, sizeof(long), Stream); //------------------------------------------------- // Surfer 7: Binary... if( !strncmp((char *)&lValue, "DSRB", 4) ) { fread(&lValue, 1, sizeof(long) , Stream); // SectionSize... fread(&lValue, 1, sizeof(long) , Stream); // Version fread(&lValue, 1, sizeof(long) , Stream); if( lValue == 0x44495247 ) // Grid-Header... { fread(&lValue , 1, sizeof(long) , Stream); // SectionSize... fread(&lValue , 1, sizeof(long) , Stream); // NX... NY = (int)lValue; fread(&lValue , 1, sizeof(long) , Stream); // NY... NX = (int)lValue; fread(&xMin , 1, sizeof(double) , Stream); // xMin... fread(&yMin , 1, sizeof(double) , Stream); // yMin... fread(&DX , 1, sizeof(double) , Stream); // DX... fread(&DY , 1, sizeof(double) , Stream); // DY... fread(&dValue , 1, sizeof(double) , Stream); // zMin... fread(&dValue , 1, sizeof(double) , Stream); // zMax... fread(&dValue , 1, sizeof(double) , Stream); // Rotation (unused)... fread(&dValue , 1, sizeof(double) , Stream); // Blank Value... fread(&lValue , 1, sizeof(long) , Stream); // ???... if( lValue == 0x41544144 ) // Load Binary Double... { fread(&lValue, 1, sizeof(long) , Stream); // SectionSize... //------------------------------------- if( !feof(Stream) && (pGrid = SG_Create_Grid(SG_DATATYPE_Double, NX, NY, DX, xMin, yMin)) != NULL ) { dLine = (double *)SG_Malloc(pGrid->Get_NX() * sizeof(double)); for(y=0; y<pGrid->Get_NY() && !feof(Stream) && Set_Progress(y, pGrid->Get_NY()); y++) { fread(dLine, pGrid->Get_NX(), sizeof(double), Stream); for(x=0; x<pGrid->Get_NX(); x++) { pGrid->Set_Value(x, y, dLine[x]); } } SG_Free(dLine); } } } } //------------------------------------------------- // Surfer 6: Binary... else if( !strncmp((char *)&lValue, "DSBB", 4) ) { fread(&sValue , 1, sizeof(short) , Stream); NX = sValue; fread(&sValue , 1, sizeof(short) , Stream); NY = sValue; fread(&xMin , 1, sizeof(double) , Stream); fread(&dValue , 1, sizeof(double) , Stream); // XMax DX = (dValue - xMin) / (NX - 1.0); fread(&yMin , 1, sizeof(double) , Stream); fread(&dValue , 1, sizeof(double) , Stream); // YMax... DY = (dValue - yMin) / (NY - 1.0); fread(&dValue , 1, sizeof(double) , Stream); // ZMin... fread(&dValue , 1, sizeof(double) , Stream); // ZMax... //--------------------------------------------- if( !feof(Stream) && (pGrid = SG_Create_Grid(SG_DATATYPE_Float, NX, NY, DX, xMin, yMin)) != NULL ) { fLine = (float *)SG_Malloc(pGrid->Get_NX() * sizeof(float)); for(y=0; y<pGrid->Get_NY() && !feof(Stream) && Set_Progress(y, pGrid->Get_NY()); y++) { fread(fLine, pGrid->Get_NX(), sizeof(float), Stream); for(x=0; x<pGrid->Get_NX(); x++) { pGrid->Set_Value(x, y, fLine[x]); } } SG_Free(fLine); } } //------------------------------------------------- // Surfer 6: ASCII... else if( !strncmp((char *)&lValue, "DSAA", 4) ) { fscanf(Stream, "%d %d" , &NX , &NY); fscanf(Stream, "%lf %lf", &xMin , &dValue); DX = (dValue - xMin) / (NX - 1.0); fscanf(Stream, "%lf %lf", &yMin , &dValue); DY = (dValue - yMin) / (NY - 1.0); fscanf(Stream, "%lf %lf", &dValue, &dValue); //--------------------------------------------- if( !feof(Stream) && (pGrid = SG_Create_Grid(SG_DATATYPE_Float, NX, NY, DX, xMin, yMin)) != NULL ) { for(y=0; y<pGrid->Get_NY() && !feof(Stream) && Set_Progress(y, pGrid->Get_NY()); y++) { for(x=0; x<pGrid->Get_NX(); x++) { fscanf(Stream, "%lf", &dValue); pGrid->Set_Value(x, y, dValue); } } } } fclose(Stream); } //----------------------------------------------------- if( pGrid ) { pGrid->Set_Name(Parameters("FILE")->asString()); pGrid->Set_NoData_Value(Parameters("NODATA")->asInt() == 0 ? NODATAVALUE : Parameters("NODATA_VAL")->asDouble()); Parameters("GRID")->Set_Value(pGrid); } return( pGrid != NULL ); }
//--------------------------------------------------------- bool CAtlas_BNA_Export::On_Execute(void) { int iShape, iPart, iPoint, iName1, iName2; FILE *Stream; TSG_Point p; CSG_Points Pts; CSG_Shape *pShape; CSG_Shapes *pShapes; CSG_String fName; //----------------------------------------------------- pShapes = Parameters("SHAPES") ->asShapes(); fName = Parameters("FILE") ->asString(); iName1 = Parameters("PNAME") ->asInt(); iName2 = Parameters("SNAME") ->asInt(); //----------------------------------------------------- if( (Stream = fopen(fName.b_str(), "w")) != NULL ) { for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { pShape = pShapes->Get_Shape(iShape); switch( pShapes->Get_Type() ) { default: break; //--------------------------------------------- case SHAPE_TYPE_Point: fprintf(Stream, "\"%s\",\"%s\",%d\n", pShape->asString(iName1), pShape->asString(iName2), 1 ); p = pShape->Get_Point(0); fprintf(Stream, "%f,%f\n", p.x, p.y); break; //--------------------------------------------- case SHAPE_TYPE_Line: for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { fprintf(Stream, "\"%s\",\"%s\",%d\n", pShape->asString(iName1), pShape->asString(iName2), -pShape->Get_Point_Count(iPart) ); for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { p = pShape->Get_Point(iPoint, iPart); fprintf(Stream, "%f,%f\n", p.x, p.y); } } break; //--------------------------------------------- case SHAPE_TYPE_Polygon: if( pShape->Get_Part_Count() > 0 && pShape->Get_Point_Count(0) > 2 ) { Pts.Clear(); for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { Pts.Add(pShape->Get_Point(iPoint, iPart)); } if( iPart > 0 ) { Pts.Add(pShape->Get_Point(0, 0)); } } if( Pts.Get_Count() > 2 ) { fprintf(Stream, "\"%s\",\"%s\",%d\n", pShape->asString(iName1), pShape->asString(iName2), Pts.Get_Count() ); for(iPoint=0; iPoint<Pts.Get_Count(); iPoint++) { fprintf(Stream, "%f,%f\n", Pts[iPoint].x, Pts[iPoint].y); } } } break; } } fclose(Stream); return( true ); } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- bool CDXF_Import::On_Execute(void) { CSG_String fName = Parameters("FILE")->asString(); Parameters("TABLES")->asTableList() ->Del_Items(); Parameters("SHAPES")->asShapesList()->Del_Items(); m_Filter = Parameters("FILTER") ->asInt(); m_dArc = Parameters("DCIRCLE") ->asDouble() * M_DEG_TO_RAD; //----------------------------------------------------- if( SG_File_Exists(fName) ) { m_pLayers = SG_Create_Table(); m_pLayers ->Fmt_Name("%s [%s]", SG_File_Get_Name(fName, false).c_str(), _TL("Layers")); m_pLayers ->Add_Field("LAYER" , SG_DATATYPE_String); m_pLayers ->Add_Field("FLAGS" , SG_DATATYPE_Int); m_pBlocks = SG_Create_Table(); m_pBlocks ->Fmt_Name("%s [%s]", SG_File_Get_Name(fName, false).c_str(), _TL("Blocks")); m_pBlocks ->Add_Field("BLOCK" , SG_DATATYPE_String); m_pBlocks ->Add_Field("FLAGS" , SG_DATATYPE_Int); m_pBlocks ->Add_Field("X" , SG_DATATYPE_Double); m_pBlocks ->Add_Field("Y" , SG_DATATYPE_Double); m_pBlocks ->Add_Field("Z" , SG_DATATYPE_Double); m_pPoints = SG_Create_Shapes(SHAPE_TYPE_Point , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Points"))); m_pPoints ->Add_Field("LAYER" , SG_DATATYPE_String); m_pPoints ->Add_Field("Z" , SG_DATATYPE_Double); m_pLines = SG_Create_Shapes(SHAPE_TYPE_Line , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Lines"))); m_pLines ->Add_Field("LAYER" , SG_DATATYPE_String); m_pLines ->Add_Field("Z1" , SG_DATATYPE_Double); m_pLines ->Add_Field("Z2" , SG_DATATYPE_Double); m_pPolyLines = SG_Create_Shapes(SHAPE_TYPE_Line , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Polylines"))); m_pPolyLines ->Add_Field("LAYER" , SG_DATATYPE_String); m_pPolyLines ->Add_Field("FLAGS" , SG_DATATYPE_Int); m_pPolygons = SG_Create_Shapes(SHAPE_TYPE_Polygon , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Polygons"))); m_pPolygons ->Add_Field("LAYER" , SG_DATATYPE_String); m_pPolygons ->Add_Field("FLAGS" , SG_DATATYPE_Int); m_pCircles = SG_Create_Shapes(SHAPE_TYPE_Line , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Circles"))); m_pCircles ->Add_Field("LAYER" , SG_DATATYPE_String); m_pCircles ->Add_Field("FLAGS" , SG_DATATYPE_Int); m_pTriangles = SG_Create_Shapes(SHAPE_TYPE_Polygon , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Triangles"))); m_pTriangles ->Add_Field("LAYER" , SG_DATATYPE_String); m_pTriangles ->Add_Field("THICK" , SG_DATATYPE_Int); m_pTriangles ->Add_Field("Z1" , SG_DATATYPE_Double); m_pTriangles ->Add_Field("Z2" , SG_DATATYPE_Double); m_pTriangles ->Add_Field("Z3" , SG_DATATYPE_Double); m_pText = SG_Create_Shapes(SHAPE_TYPE_Point , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Text"))); m_pText ->Add_Field("LAYER" , SG_DATATYPE_String); m_pText ->Add_Field("Z" , SG_DATATYPE_Double); m_pText ->Add_Field("TEXT" , SG_DATATYPE_String); m_pText ->Add_Field("HEIGHT", SG_DATATYPE_Int); m_pText ->Add_Field("ANGLE" , SG_DATATYPE_Double); m_pText ->Add_Field("APX" , SG_DATATYPE_Double); m_pText ->Add_Field("APY" , SG_DATATYPE_Double); m_pText ->Add_Field("APZ" , SG_DATATYPE_Double); m_pText ->Add_Field("SCALE" , SG_DATATYPE_Double); m_pText ->Add_Field("HJUST" , SG_DATATYPE_Int); m_pText ->Add_Field("VJUST" , SG_DATATYPE_Int); m_pText ->Add_Field("STYLE" , SG_DATATYPE_String); m_pText ->Add_Field("FLAGS" , SG_DATATYPE_Int); //------------------------------------------------- m_Offset.x = 0.0; m_Offset.y = 0.0; m_Offset.z = 0.0; m_pPolyLine = NULL; DL_Dxf *pDXF = new DL_Dxf(); pDXF->in(fName.b_str(), this); delete(pDXF); //------------------------------------------------- ADD_RESULT("TABLES", m_pLayers); ADD_RESULT("TABLES", m_pBlocks); ADD_RESULT("SHAPES", m_pPoints); ADD_RESULT("SHAPES", m_pLines); ADD_RESULT("SHAPES", m_pPolyLines); ADD_RESULT("SHAPES", m_pPolygons); ADD_RESULT("SHAPES", m_pCircles); ADD_RESULT("SHAPES", m_pTriangles); ADD_RESULT("SHAPES", m_pText); } //----------------------------------------------------- return( Parameters("SHAPES")->asShapesList()->Get_Item_Count() > 0 ); }