本文整理汇总了C++中SHPClose函数的典型用法代码示例。如果您正苦于以下问题:C++ SHPClose函数的具体用法?C++ SHPClose怎么用?C++ SHPClose使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SHPClose函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: display_info
static int display_info(const char * fpath, const struct stat * sb, int tflag, struct FTW * ftwbuf)
{
if (fpath[ftwbuf->base] == '.') return 0;
if (strcmp(fpath + strlen(fpath) - 4, ".dbf") != 0) return 0;
char file[400];
strncpy(file, fpath + strlen(data_path), 400);
file[strlen(file)-4] = 0;
DBFHandle dbf = DBFOpen(fpath, "rb");
SHPHandle shp = SHPOpen(fpath, "rb");
general_count++;
char * formatc = mg_get_var(dconn, "format");
int json = 0;
if (formatc != NULL && strcmp(formatc, "json") == 0)
json = 1;
free(formatc);
if (json)
{
mg_printf(dconn, "%s\n {", ((general_count==1) ? "" : ","));
mg_printf(dconn, "\"file\":\"%s\"", file);
if (dbf) mg_printf(dconn, ", \"dbfRecords\":%d", dbf->nRecords);
if (dbf) mg_printf(dconn, ", \"dbfFields\":%d", dbf->nFields);
mg_printf(dconn, ", \"image 0\": \"/image?file=%s&id=0\"", file);
mg_printf(dconn, ", \"full image\": \"/image?file=%s\"", file);
mg_printf(dconn, "}");
}
else
{
mg_printf(dconn, "<tr>");
mg_printf(dconn, "<td>%s</td>", file);
if (dbf) mg_printf(dconn, "<td><a href='/shapefiles/fields?file=%s'>fields</a></td>", file);
if (shp) mg_printf(dconn, "<td><a href='/shapefiles/png?file=%s'>image</a></td>\n", file);
mg_printf(dconn, "</tr>");
}
if (shp) SHPClose(shp);
if (dbf) DBFClose(dbf);
return 0; // To tell nftw() to continue
}
示例2: Java_org_maptools_shapelib_android_util_TestUtils_createShapefile
jboolean Java_org_maptools_shapelib_android_util_TestUtils_createShapefile(JNIEnv * env, jclass clazz,
jstring file, jobject listObject) {
// create a shapefile and dbf (e.g. /sdcard/foo/bar)
const char *fileStr = (*env)->GetStringUTFChars(env, file, 0);
SHPHandle hSHP = SHPCreate(fileStr, SHPT_POINT);
DBFHandle hDBF = DBFCreate(fileStr);
// define the shapefile attributes
DBFAddField(hDBF, "name", FTString, 25, 0);
DBFAddField(hDBF, "height", FTDouble, 8, 8);
DBFAddField(hDBF, "apples", FTInteger, 1, 0);
process(env, hSHP, hDBF, file, listObject);
SHPClose(hSHP);
DBFClose(hDBF);
}
示例3: Rshapeinfo1
SEXP Rshapeinfo1(SEXP shpname)
{
SEXP res, nms;
SHPHandle hSHP;
int nShapeType, nEntities, i, pc=0;
double adfMinBound[4], adfMaxBound[4];
PROTECT(res = NEW_LIST(5)); pc++;
PROTECT(nms = NEW_CHARACTER(5)); pc++;
SET_STRING_ELT(nms, 0, COPY_TO_USER_STRING("fname"));
SET_STRING_ELT(nms, 1, COPY_TO_USER_STRING("type"));
SET_STRING_ELT(nms, 2, COPY_TO_USER_STRING("entities"));
SET_STRING_ELT(nms, 3, COPY_TO_USER_STRING("minbounds"));
SET_STRING_ELT(nms, 4, COPY_TO_USER_STRING("maxbounds"));
setAttrib(res, R_NamesSymbol, nms);
SET_VECTOR_ELT(res, 0, NEW_CHARACTER(1));
SET_VECTOR_ELT(res, 1, NEW_INTEGER(1));
SET_VECTOR_ELT(res, 2, NEW_INTEGER(1));
SET_VECTOR_ELT(res, 3, NEW_NUMERIC(4));
SET_VECTOR_ELT(res, 4, NEW_NUMERIC(4));
SET_STRING_ELT(VECTOR_ELT(res, 0), 0, STRING_ELT(shpname, 0));
/* const char *pszPlus; */
/* -------------------------------------------------------------------- */
/* Open the passed shapefile. */
/* -------------------------------------------------------------------- */
hSHP = SHPOpen(CHAR(STRING_ELT(shpname, 0)), "rb" );
if( hSHP == NULL ) error("Error opening SHP file");
/* -------------------------------------------------------------------- */
/* Print out the file bounds. */
/* -------------------------------------------------------------------- */
SHPGetInfo( hSHP, &nEntities, &nShapeType, adfMinBound, adfMaxBound );
INTEGER_POINTER(VECTOR_ELT(res, 1))[0] = nShapeType;
INTEGER_POINTER(VECTOR_ELT(res, 2))[0] = nEntities;
for (i=0; i<4; i++) {
NUMERIC_POINTER(VECTOR_ELT(res, 3))[i] = adfMinBound[i];
NUMERIC_POINTER(VECTOR_ELT(res, 4))[i] = adfMaxBound[i];
}
SHPClose( hSHP );
UNPROTECT(pc);
return(res);
}
示例4: readoutlets
// Function to read outlets from a shapefile
int readoutlets(char *outletsfile, int *noutlets, double*& x, double*& y)
{
SHPHandle shp;
shp = SHPOpen(outletsfile, "rb");
if (shp != NULL) {
int nEntities = 0;
int nShapeType = 0;
SHPGetInfo(shp, &nEntities, &nShapeType, NULL, NULL );
if (nShapeType != SHPT_POINT) {
fprintf(stderr, "Outlets shapefile %s is not a point shapefile\n", outletsfile);
fflush(stderr);
return 1;
}
long p_size;
long countPts = 0;
for( int i=0; i<nEntities; i++) {
SHPObject * shape = SHPReadObject(shp, i);
countPts += shape->nVertices;
SHPDestroyObject(shape);
}
x = new double[countPts];
y = new double[countPts];
int nxy=0;
for( int i=0; i<nEntities; i++) {
SHPObject * shape = SHPReadObject(shp, i);
p_size = shape->nVertices;
for( int j=0; j<p_size; j++) {
x[nxy] = shape->padfX[j];
y[nxy] = shape->padfY[j];
nxy++;
}
SHPDestroyObject(shape);
}
*noutlets=nxy;
SHPClose(shp);
return 0;
}
else {
fprintf(stderr, "Error opening outlets shapefile %s.\n", outletsfile);
fflush(stderr);
return 1;
}
}
示例5: Rshapeinfo
void Rshapeinfo(char **shpnm, int *Shapetype, int *Entities, double
*MinBound, double *MaxBound)
{
SHPHandle hSHP;
int nShapeType, nEntities, i;
double adfMinBound[4], adfMaxBound[4];
/* const char *pszPlus; */
/* -------------------------------------------------------------------- */
/* Open the passed shapefile. */
/* -------------------------------------------------------------------- */
hSHP = SHPOpen( shpnm[0] , "rb" );
if( hSHP == NULL )
{
/* REprintf( "Unable to open:%s\n", shpnm[0] );
exit( 1 ); */
error("No such file");
}
/* -------------------------------------------------------------------- */
/* Print out the file bounds. */
/* -------------------------------------------------------------------- */
SHPGetInfo( hSHP, &nEntities, &nShapeType, adfMinBound, adfMaxBound );
*Entities = nEntities;
*Shapetype = nShapeType;
for (i=0;i<4;i++){
MinBound[i]=adfMinBound[i];
MaxBound[i]=adfMaxBound[i];
}
/* Rprintf ("Info for %s\n", shpnm[0]);
Rprintf("Shapefile Type: %s(%d) # of Shapes: %ld\n\n",
SHPTypeName( nShapeType ), nShapeType, nEntities );
Rprintf("File Bounds: (%15.10lg,%15.10lg)\n\t(%15.10lg,%15.10lg)\n",
MinBound[0], MinBound[1], MaxBound[0], MaxBound[1] );*/
SHPClose( hSHP );
return;
}
示例6: ShpLoaderDestroy
void
ShpLoaderDestroy(SHPLOADERSTATE *state)
{
/* Destroy a state object created with ShpLoaderOpenShape */
int i;
if (state != NULL)
{
if (state->hSHPHandle)
SHPClose(state->hSHPHandle);
if (state->hDBFHandle)
DBFClose(state->hDBFHandle);
if (state->field_names)
{
for (i = 0; i < state->num_fields; i++)
free(state->field_names[i]);
free(state->field_names);
}
if (state->pgfieldtypes)
{
for (i = 0; i < state->num_fields; i++)
free(state->pgfieldtypes[i]);
free(state->pgfieldtypes);
}
if (state->types)
free(state->types);
if (state->widths)
free(state->widths);
if (state->precisions)
free(state->precisions);
if (state->col_names)
free(state->col_names);
/* Free any column map fieldnames if specified */
colmap_clean(&state->column_map);
/* Free the state itself */
free(state);
}
}
示例7: find_file_shp
void find_file_shp(char *name,char *name_metadata)
{
FILE * metadados;
metadados = fopen (name_metadata,"a");
char shp_plus_in_folder[100];
char shp_plus[30];
SHPHandle arquivo_shp;
strcpy (shp_plus,name);
strcat (shp_plus,".shp");
sprintf(shp_plus_in_folder,"%s",shp_plus);//Para o IGC
//abre o shp e verifica se o arquivo existe
arquivo_shp=SHPOpen(shp_plus_in_folder, "r");
if (arquivo_shp==NULL){
printf("Nao consegui abrir %s na pasta SHP (IGC)\n",shp_plus_in_folder);
fprintf(metadados,"Nao consegui abrir %s na pasta SHP (IGC)\n",shp_plus_in_folder);
exit(0);
}
//fim abre shp
strcpy (name,shp_plus_in_folder);
SHPClose(arquivo_shp);
fclose(metadados);
}
示例8: isshape
int isshape(char *inFile)
{
char *ext = findExt(inFile);
if (ext && strcmp_case(ext,".shp")!=0) {
return FALSE;
}
char *dbaseFile, *basename;
int isShape = 0;
int nEntities, pointType;
DBFHandle dbase;
SHPHandle shape;
dbaseFile = (char *)MALLOC(sizeof(char)*(strlen(inFile)+5));
basename = get_basename(inFile);
sprintf(dbaseFile, "%s.dbf", basename);
dbase = DBFOpen(dbaseFile, "r+b");
shape = SHPOpen(inFile, "r+b");
if (dbase != NULL && shape != NULL) {
SHPGetInfo(shape, &nEntities, &pointType, NULL, NULL);
if (nEntities >= 1 &&
(pointType == SHPT_POLYGON ||
pointType == SHPT_POINT ||
pointType == SHPT_ARC ||
pointType == SHPT_MULTIPOINT )
)
{
isShape = 1;
}
}
if (shape) SHPClose(shape);
if (dbase) DBFClose(dbase);
FREE(basename);
FREE(dbaseFile);
return isShape;
}
示例9: shape_load_countries
countries_v
shape_load_countries(const char* filename) {
countries_v countries;
kv_init(countries);
double adfMinBound[4],
adfMaxBound[4];
// Read file
SHPHandle hSHP = SHPOpen( filename, "rb" );
if(hSHP == NULL) goto end_loading;
// Print shape bounds
int country_count, shapes_vype;
SHPGetInfo( hSHP, &country_count, &shapes_vype, adfMinBound, adfMaxBound );
fprintf(stderr, "Load %d countries\n", country_count);
// Iterate through countries
for(int i = 0; i < country_count; i++ ) {
SHPObject *shp = SHPReadObject(hSHP, i);
if(shp == NULL) goto end_loading;
if(shp->nParts == 0) continue;
// first part starts at point 0
if(shp->panPartStart[0] != 0) goto end_loading;
// collect parts of country
shapes_v shapes;
kv_init(shapes);
shapes.min = (point_t){shp->dfXMin, shp->dfYMin};
shapes.max = (point_t){shp->dfXMax, shp->dfYMax};
uint32_t parts = shp->nParts;
double k = 0.0;
for (uint32_t j=0; j<parts; j++) {
// start index
uint32_t s = shp->panPartStart[j];
// end index - start of next minus one, or end
uint32_t e = (j+1 < parts) ?
shp->panPartStart[j+1]:
shp->nVertices;
shape_v shape;
kv_init(shape);
// collect points of part
for(uint32_t i=s; i<e; i++){
point_t p = (point_t){shp->padfX[i], shp->padfY[i]};
kv_push(point_t, shape, p);
// cumulitive average for center
if(k>=1.0) {
shapes.center.x = (k-1.0)/k*shapes.center.x + p.x/k;
shapes.center.y = (k-1.0)/k*shapes.center.y + p.y/k;
}else {
shapes.center.x = p.x;
shapes.center.y = p.y;
}
k+=1.0;
}
kv_push(shape_v, shapes, shape);
}
SHPDestroyObject( shp );
kv_push(shapes_v, countries, shapes);
}
SHPClose( hSHP );
end_loading:
return countries;
}
示例10: main
//.........这里部分代码省略.........
psShape = SHPReadObject( hSHP, i );
if( psShape == NULL )
{
fprintf( stderr,
"Unable to read shape %d, terminating object reading.\n",
i );
break;
}
if( psShape->bMeasureIsUsed )
printf( "\nShape:%d (%s) nVertices=%d, nParts=%d\n"
" Bounds:(%.15g,%.15g, %.15g, %.15g)\n"
" to (%.15g,%.15g, %.15g, %.15g)\n",
i, SHPTypeName(psShape->nSHPType),
psShape->nVertices, psShape->nParts,
psShape->dfXMin, psShape->dfYMin,
psShape->dfZMin, psShape->dfMMin,
psShape->dfXMax, psShape->dfYMax,
psShape->dfZMax, psShape->dfMMax );
else
printf( "\nShape:%d (%s) nVertices=%d, nParts=%d\n"
" Bounds:(%.15g,%.15g, %.15g)\n"
" to (%.15g,%.15g, %.15g)\n",
i, SHPTypeName(psShape->nSHPType),
psShape->nVertices, psShape->nParts,
psShape->dfXMin, psShape->dfYMin,
psShape->dfZMin,
psShape->dfXMax, psShape->dfYMax,
psShape->dfZMax );
if( psShape->nParts > 0 && psShape->panPartStart[0] != 0 )
{
fprintf( stderr, "panPartStart[0] = %d, not zero as expected.\n",
psShape->panPartStart[0] );
}
for( j = 0, iPart = 1; j < psShape->nVertices; j++ )
{
const char *pszPartType = "";
if( j == 0 && psShape->nParts > 0 )
pszPartType = SHPPartTypeName( psShape->panPartType[0] );
if( iPart < psShape->nParts
&& psShape->panPartStart[iPart] == j )
{
pszPartType = SHPPartTypeName( psShape->panPartType[iPart] );
iPart++;
pszPlus = "+";
}
else
pszPlus = " ";
if( psShape->bMeasureIsUsed )
printf(" %s (%.15g,%.15g, %.15g, %.15g) %s \n",
pszPlus,
psShape->padfX[j],
psShape->padfY[j],
psShape->padfZ[j],
psShape->padfM[j],
pszPartType );
else
printf(" %s (%.15g,%.15g, %.15g) %s \n",
pszPlus,
psShape->padfX[j],
psShape->padfY[j],
psShape->padfZ[j],
pszPartType );
}
if( bValidate )
{
int nAltered = SHPRewindObject( hSHP, psShape );
if( nAltered > 0 )
{
printf( " %d rings wound in the wrong direction.\n",
nAltered );
nInvalidCount++;
}
}
SHPDestroyObject( psShape );
}
SHPClose( hSHP );
if( bValidate )
{
printf( "%d object has invalid ring orderings.\n", nInvalidCount );
}
#ifdef USE_DBMALLOC
malloc_dump(2);
#endif
exit( 0 );
}
示例11: main
int main( int argc, char ** argv )
{
SHPHandle old_SHP, new_SHP;
DBFHandle old_DBF, new_DBF;
int nShapeType, nEntities, nVertices, nParts, *panParts, i, iPart;
double *padVertices, adBounds[4];
const char *pszPlus;
DBFFieldType idfld_type;
int idfld, nflds;
char kv[257] = "";
char idfldName[120] = "";
char fldName[120] = "";
char shpFileName[120] = "";
char dbfFileName[120] = "";
char *DBFRow = NULL;
int Cpan[2] = { 0,0 };
int byRing = 1;
PT oCentrd, ringCentrd;
SHPObject *psCShape, *cent_pt;
double oArea = 0.0, oLen = 0.0;
if( argc < 2 )
{
printf( "shpdata shp_file \n" );
exit( 1 );
}
old_SHP = SHPOpen (argv[1], "rb" );
old_DBF = DBFOpen (argv[1], "rb");
if( old_SHP == NULL || old_DBF == NULL )
{
printf( "Unable to open old files:%s\n", argv[1] );
exit( 1 );
}
SHPGetInfo( old_SHP, &nEntities, &nShapeType, NULL, NULL );
for( i = 0; i < nEntities; i++ )
{
int res ;
psCShape = SHPReadObject( old_SHP, i );
if ( byRing == 1 ) {
int ring, prevStart, ringDir;
double ringArea;
prevStart = psCShape->nVertices;
for ( ring = (psCShape->nParts - 1); ring >= 0; ring-- ) {
SHPObject *psO;
int j, numVtx, rStart;
rStart = psCShape->panPartStart[ring];
if ( ring == (psCShape->nParts -1) )
{ numVtx = psCShape->nVertices - rStart; }
else
{ numVtx = psCShape->panPartStart[ring+1] - rStart; }
printf ("(shpdata) Ring(%d) (%d for %d) \n", ring, rStart, numVtx);
psO = SHPClone ( psCShape, ring, ring + 1 );
ringDir = SHPRingDir_2d ( psO, 0 );
ringArea = RingArea_2d (psO->nVertices,(double*) psO->padfX,
(double*) psO->padfY);
RingCentroid_2d ( psO->nVertices, (double*) psO->padfX,
(double*) psO->padfY, &ringCentrd, &ringArea);
printf ("(shpdata) Ring %d, %f Area %d dir \n",
ring, ringArea, ringDir );
SHPDestroyObject ( psO );
printf ("(shpdata) End Ring \n");
} /* (ring) [0,nParts */
} /* by ring */
oArea = SHPArea_2d ( psCShape );
oLen = SHPLength_2d ( psCShape );
oCentrd = SHPCentrd_2d ( psCShape );
printf ("(shpdata) Part (%d) %f Area %f length, C (%f,%f)\n",
i, oArea, oLen, oCentrd.x, oCentrd.y );
}
SHPClose( old_SHP );
DBFClose( old_DBF );
printf ("\n");
}
示例12: getPolysFromShapefile
bool getPolysFromShapefile(QString const &fileShp,
QList<QList<Vec2d> > &listPolygons)
{
SHPHandle hSHP = SHPOpen(fileShp.toLocal8Bit().data(),"rb");
if(hSHP == NULL) {
qDebug() << "ERROR: Could not open shape file";
return false;
}
if(hSHP->nShapeType != SHPT_POLYGON) {
qDebug() << "ERROR: Wrong shape file type:";
qDebug() << "ERROR: Expected POLYGON";
return false;
}
size_t nRecords = hSHP->nRecords;
double xMax = hSHP->adBoundsMax[0];
double yMax = hSHP->adBoundsMax[1];
double xMin = hSHP->adBoundsMin[0];
double yMin = hSHP->adBoundsMin[1];
qDebug() << "INFO: Bounds: x: " << xMin << "<>" << xMax;
qDebug() << "INFO: Bounds: y: " << yMin << "<>" << yMax;
qDebug() << "INFO: Found " << nRecords << "POLYGONS";
qDebug() << "INFO: Reading in data...";
qDebug() << "INFO: Creating color list...";
QStringList listColors;
for(size_t i=0; i < nRecords; i++) {
QString strColor = QString::number(i,16);
while(strColor.length() < 6) { // pad with zeros
strColor.prepend("0");
}
strColor.prepend("#");
listColors.push_back(strColor);
}
// create a list of polygons we can paint
SHPObject * pSHPObj;
for(size_t i=0; i < nRecords; i++)
{ // for each object
pSHPObj = SHPReadObject(hSHP,i);
size_t nParts = pSHPObj->nParts;
// build a list of start and end pts
QList<int> listStartPts;
QList<int> listEndB4Pts;
for(size_t j=0; j < nParts-1; j++) {
listStartPts.push_back(pSHPObj->panPartStart[j]);
listEndB4Pts.push_back(pSHPObj->panPartStart[j+1]);
}
listStartPts.push_back(pSHPObj->panPartStart[nParts-1]);
listEndB4Pts.push_back(pSHPObj->nVertices);
// build polys from start/end pts
for(int j=0; j < listStartPts.size(); j++)
{
QList<Vec2d> listPts;
size_t sIx = listStartPts[j];
size_t eIx = listEndB4Pts[j];
for(size_t k=sIx; k < eIx; k++) {
listPts.push_back(Vec2d(pSHPObj->padfX[k]+180,
(pSHPObj->padfY[k]-90)*-1,
QColor(listColors[i])));
}
listPolygons.push_back(listPts);
}
SHPDestroyObject(pSHPObj);
}
SHPClose(hSHP);
return true;
}
示例13: QFileInfo
void dibSHP::procesFile(Document_Interface *doc)
{
int num_ent, st;
double min_bound[4], max_bound[4];
currDoc = doc;
QFileInfo fi = QFileInfo(fileedit->text());
if (fi.suffix() != "shp") {
QMessageBox::critical ( this, "Shapefile", QString(tr("The file %1 not have extension .shp")).arg(fileedit->text()) );
return;
}
if (!fi.exists() ) {
QMessageBox::critical ( this, "Shapefile", QString(tr("The file %1 not exist")).arg(fileedit->text()) );
return;
}
QString file = fi.canonicalFilePath ();
SHPHandle sh = SHPOpen( file.toLocal8Bit(), "rb" );
SHPGetInfo( sh, &num_ent, &st, min_bound, max_bound );
DBFHandle dh = DBFOpen( file.toLocal8Bit(), "rb" );
if (radiolay1->isChecked()) {
layerF = -1;
attdata.layer = currDoc->getCurrentLayer();
} else {
layerF = DBFGetFieldIndex( dh, (layerdata->currentText()).toLatin1().data() );
layerT = DBFGetFieldInfo( dh, layerF, NULL, NULL, NULL );
}
if (radiocol1->isChecked())
colorF = -1;
else {
colorF = DBFGetFieldIndex( dh, (colordata->currentText()).toLatin1().data() );
colorT = DBFGetFieldInfo( dh, colorF, NULL, NULL, NULL );
}
if (radioltype1->isChecked())
ltypeF = -1;
else {
ltypeF = DBFGetFieldIndex( dh, (ltypedata->currentText()).toLatin1().data() );
ltypeT = DBFGetFieldInfo( dh, ltypeF, NULL, NULL, NULL );
}
if (radiolwidth1->isChecked())
lwidthF = -1;
else {
lwidthF = DBFGetFieldIndex( dh, (lwidthdata->currentText()).toLatin1().data() );
lwidthT = DBFGetFieldInfo( dh, lwidthF, NULL, NULL, NULL );
}
if (radiopoint1->isChecked())
pointF = -1;
else {
pointF = DBFGetFieldIndex( dh, (pointdata->currentText()).toLatin1().data() );
pointT = DBFGetFieldInfo( dh, pointF, NULL, NULL, NULL );
}
currlayer =currDoc->getCurrentLayer();
for( int i = 0; i < num_ent; i++ ) {
sobject= NULL;
sobject = SHPReadObject( sh, i );
if (sobject) {
switch (sobject->nSHPType) {
case SHPT_NULL:
break;
case SHPT_POINT:
case SHPT_POINTM: //2d point with measure
case SHPT_POINTZ: //3d point
readPoint(dh, i);
break;
case SHPT_MULTIPOINT:
case SHPT_MULTIPOINTM:
case SHPT_MULTIPOINTZ:
break;
case SHPT_ARC:
case SHPT_ARCM:
case SHPT_ARCZ:
readPolyline(dh, i);
break;
case SHPT_POLYGON:
case SHPT_POLYGONM:
case SHPT_POLYGONZ:
readPolylineC(dh, i);
case SHPT_MULTIPATCH:
readMultiPolyline(dh, i);
default:
break;
}
SHPDestroyObject(sobject);
}
}
SHPClose( sh );
DBFClose( dh );
currDoc->setLayer(currlayer);
}
示例14: main
//.........这里部分代码省略.........
{
char pszFieldName[12];
int pnWidth;
int pnDecimals;
DBFFieldType ft = DBFGetFieldInfo(d, i, pszFieldName, &pnWidth, &pnDecimals);
switch (ft)
{
case FTString:
fprintf(fp, ", %s VARCHAR(%d)", pszFieldName, pnWidth);
break;
case FTInteger:
fprintf(fp, ", %s INT", pszFieldName);
break;
case FTDouble:
fprintf(fp, ", %s FLOAT(15,10)", pszFieldName);
break;
case FTLogical:
break;
case FTInvalid:
break;
}
}*/
fprintf(fp, " <Document>\n");
int i;
for (i = 0 ; i < nRecordCount ; i++)
{
fprintf(fp, " <Placemark>\n");
fprintf(fp, " <name>%s</name>\n", (char *)DBFReadStringAttribute(d, i, 2));
fprintf(fp, " <Polygon>\n");
fprintf(fp, " <extrude>1</extrude>\n");
fprintf(fp, " <altitudeMode>relativeToGround</altitudeMode>\n");
fprintf(fp, " <outerBoundaryIs>\n");
fprintf(fp, " <LinearRing>\n");
fprintf(fp, " <coordinates>\n");
SHPObject *psShape = SHPReadObject(h, i);
int j, iPart;
for (j = 0, iPart = 1; j < psShape->nVertices; j++)
{
fprintf(fp, "%f,%f,100\n", psShape->padfX[j], psShape->padfY[j]);
}
fprintf(fp, " </coordinates>\n");
fprintf(fp, " </LinearRing>\n");
fprintf(fp, " </outerBoundaryIs>\n");
fprintf(fp, " </Polygon>\n");
fprintf(fp, " </Placemark>\n");
}
fprintf(fp, " </Document>\n");
/*int nShapeType;
int nEntities;
const char *pszPlus;
double adfMinBound[4], adfMaxBound[4];
SHPGetInfo(h, &nEntities, &nShapeType, adfMinBound, adfMaxBound);
printf("SHP has %d entities\n", nEntities);
for (i = 0; i < nEntities; i++)
{
SHPObject *psShape = SHPReadObject(h, i);
//fprintf(fp, "INSERT INTO edges (id) VALUES (%d);\n", i+1);
int j, iPart;
for (j = 0, iPart = 1; j < psShape->nVertices; j++)
{
const char *pszPartType = "";
if (j == 0 && psShape->nParts > 0) pszPartType = SHPPartTypeName(psShape->panPartType[0]);
if (iPart < psShape->nParts && psShape->panPartStart[iPart] == j)
{
pszPartType = SHPPartTypeName(psShape->panPartType[iPart]);
iPart++;
pszPlus = "+";
}
else
pszPlus = " ";
//if (j%500==0)
// fprintf(fp, "%sINSERT INTO vertexes (edge_id, x, y) VALUES (", (j!=0 ? ");\n": ""));
//else
// fprintf(fp, "),(");
//fprintf(fp, "%d, %f, %f", i+1, psShape->padfX[j], psShape->padfY[j]);
}
//fprintf(fp, ");\n");
SHPDestroyObject(psShape);
}*/
fprintf(fp, "</kml>\n");
printf("all done\n");
fclose(fp);
if (h != NULL) SHPClose(h);
if (d != NULL) DBFClose(d);
}
示例15: GetLayerCount
//.........这里部分代码省略.........
hSHP = SHPCreateLL( pszFilename, nShapeType, (SAHooks*) VSI_SHP_GetHook(b2GBLimit) );
if( hSHP == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Failed to open Shapefile `%s'.\n",
pszFilename );
CPLFree( pszFilename );
CPLFree( pszFilenameWithoutExt );
return NULL;
}
SHPSetFastModeReadObject( hSHP, TRUE );
CPLFree( pszFilename );
}
else
hSHP = NULL;
/* -------------------------------------------------------------------- */
/* Has a specific LDID been specified by the caller? */
/* -------------------------------------------------------------------- */
const char *pszLDID = CSLFetchNameValue( papszOptions, "ENCODING" );
/* -------------------------------------------------------------------- */
/* Create a DBF file. */
/* -------------------------------------------------------------------- */
pszFilename = CPLStrdup(CPLFormFilename( NULL, pszFilenameWithoutExt, "dbf" ));
if( pszLDID != NULL )
hDBF = DBFCreateLL( pszFilename, pszLDID, (SAHooks*) VSI_SHP_GetHook(b2GBLimit) );
else
hDBF = DBFCreateLL( pszFilename, "LDID/87",(SAHooks*) VSI_SHP_GetHook(b2GBLimit) );
if( hDBF == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Failed to open Shape DBF file `%s'.\n",
pszFilename );
CPLFree( pszFilename );
CPLFree( pszFilenameWithoutExt );
SHPClose(hSHP);
return NULL;
}
CPLFree( pszFilename );
/* -------------------------------------------------------------------- */
/* Create the .prj file, if required. */
/* -------------------------------------------------------------------- */
if( poSRS != NULL )
{
char *pszWKT = NULL;
CPLString osPrjFile = CPLFormFilename( NULL, pszFilenameWithoutExt, "prj");
VSILFILE *fp;
/* the shape layer needs it's own copy */
poSRS = poSRS->Clone();
poSRS->morphToESRI();
if( poSRS->exportToWkt( &pszWKT ) == OGRERR_NONE
&& (fp = VSIFOpenL( osPrjFile, "wt" )) != NULL )
{
VSIFWriteL( pszWKT, strlen(pszWKT), 1, fp );
VSIFCloseL( fp );
}
CPLFree( pszWKT );
poSRS->morphFromESRI();
}
/* -------------------------------------------------------------------- */
/* Create the layer object. */
/* -------------------------------------------------------------------- */
OGRShapeLayer *poLayer;
/* OGRShapeLayer constructor expects a filename with an extension (that could be */
/* random actually), otherwise this is going to cause problems with layer */
/* names that have a dot (not speaking about the one before the shp) */
pszFilename = CPLStrdup(CPLFormFilename( NULL, pszFilenameWithoutExt, "shp" ));
poLayer = new OGRShapeLayer( this, pszFilename, hSHP, hDBF, poSRS, TRUE, TRUE,
eType );
CPLFree( pszFilenameWithoutExt );
CPLFree( pszFilename );
poLayer->SetResizeAtClose( CSLFetchBoolean( papszOptions, "RESIZE", FALSE ) );
poLayer->CreateSpatialIndexAtClose( CSLFetchBoolean( papszOptions, "SPATIAL_INDEX", FALSE ) );
poLayer->SetModificationDate(
CSLFetchNameValue( papszOptions, "DBF_DATE_LAST_UPDATE" ) );
/* -------------------------------------------------------------------- */
/* Add layer to data source layer list. */
/* -------------------------------------------------------------------- */
AddLayer(poLayer);
return poLayer;
}