本文整理汇总了C++中SHPGetInfo函数的典型用法代码示例。如果您正苦于以下问题:C++ SHPGetInfo函数的具体用法?C++ SHPGetInfo怎么用?C++ SHPGetInfo使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SHPGetInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SHPGetInfo
bool ShapelibProxy::getTypeAndCount(const ShapelibHandle &handle, std::string &errorMessage,
ArcProxyLib::FeatureType &featureType, int &count)
{
int type;
SHPGetInfo(handle.getShpHandle(), &count, &type, NULL, NULL);
featureType = ArcProxyLib::UNKNOWN;
switch (type)
{
case SHPT_POINT: // fall through
case SHPT_POINTZ:
featureType = ArcProxyLib::POINT;
break;
case SHPT_MULTIPOINT: // fall through
case SHPT_MULTIPOINTZ:
featureType = ArcProxyLib::MULTIPOINT;
break;
case SHPT_ARC: // fall through
case SHPT_ARCZ:
featureType = ArcProxyLib::POLYLINE;
break;
case SHPT_POLYGON: // fall through
case SHPT_POLYGONZ:
featureType = ArcProxyLib::POLYGON;
break;
default:
errorMessage = "Unknown shape type";
return false;
}
return true;
}
示例2: loadMapData
void loadMapData(std::string path, QPolygonF* poly)
{
SHPHandle shp = SHPOpen(path.c_str(), "rb");
if (shp != 0) {
qDebug() << "Loaded map: " << path.c_str();
} else {
qDebug() << "Could not load map: " << path.c_str();
return;
}
int entities, type;
double minBound[4], maxBound[4];
SHPGetInfo(shp, &entities, &type, minBound, maxBound);
// qDebug() << "Type: " << type << " Entities: " << entities;
SHPObject* o = SHPReadObject(shp, 0);
int parts = o->nParts;
// qDebug() << "Parts: " << parts;
int currentPart = 0;
int start = o->panPartStart[currentPart];
int end = parts == 1 ? o->nVertices : o->panPartStart[currentPart + 1];
// qDebug() << "Start: " << start << " End: " << end << " Vertices: " << o->nVertices;
for(int i = start; i < end; i++) {
double x = o->padfX[i];
double y = o->padfY[i];
*poly << QPointF(x, y);
}
}
示例3: UTF8ToLocal
bool vtUtilityMap::ImportPolesFromSHP(const char *fname)
{
SHPHandle hSHP;
int nEntities, nShapeType;
DPoint2 point;
// SHPOpen doesn't yet support utf-8 or wide filenames, so convert
vtString fname_local = UTF8ToLocal(fname);
hSHP = SHPOpen(fname_local, "rb");
if (!hSHP)
return false;
SHPGetInfo(hSHP, &nEntities, &nShapeType, NULL, NULL);
if (nShapeType != SHPT_POINT)
return false;
for (int i = 0; i < nEntities; i++)
{
SHPObject *psShape = SHPReadObject(hSHP, i);
point.x = psShape->padfX[0];
point.y = psShape->padfY[0];
vtPole *pole = new vtPole;
pole->m_p = point;
m_Poles.Append(pole);
SHPDestroyObject(psShape);
}
SHPClose(hSHP);
return true;
}
示例4: build_rtree
//CAREFUL: note how adding things to the tree can change the root
// Must not ever use cache a value of the root pointer if there's any
// chance that the tree needs to be expanded!
void build_rtree (struct Node **root, SHPHandle sHP) {
int nEntities;
intptr_t i;
SHPObject *psCShape;
struct Rect bbox_shape;
SHPGetInfo(sHP, &nEntities, NULL, NULL, NULL);
for( i = 0; i < nEntities; i++ ) {
psCShape = SHPReadObject ( sHP, i );
if (psCShape != NULL) {
bbox_shape.boundary[0]=(RectReal) psCShape->dfXMin;
bbox_shape.boundary[1]=(RectReal) psCShape->dfYMin;
bbox_shape.boundary[2]=(RectReal) psCShape->dfXMax;
bbox_shape.boundary[3]=(RectReal) psCShape->dfYMax;
SHPDestroyObject ( psCShape );
// Only insert the rect if it will not fail the assertion in
// Xastir_RTreeInsertRect --- this will cause us to ignore any shapes that
// have invalid bboxes (or that return invalid bboxes from shapelib
// for whatever reason
if (bbox_shape.boundary[0] <= bbox_shape.boundary[2] &&
bbox_shape.boundary[1] <= bbox_shape.boundary[3]) {
Xastir_RTreeInsertRect(&bbox_shape, (void *)(i+1), root, 0);
}
}
}
}
示例5: parse
void parse(const std::string& path, Visitor& visitor) const
{
SHPHandle shpFile = SHPOpen(path.c_str(), "rb");
if (shpFile == NULL)
throw std::domain_error("Cannot open shp file.");
int shapeType, entityCount;
double adfMinBound[4], adfMaxBound[4];
SHPGetInfo(shpFile, &entityCount, &shapeType, adfMinBound, adfMaxBound);
DBFHandle dbfFile = DBFOpen(path.c_str(), "rb");
if (dbfFile == NULL)
throw std::domain_error("Cannot open dbf file.");
if (DBFGetFieldCount(dbfFile) == 0)
throw std::domain_error("There are no fields in dbf table.");
if (entityCount != DBFGetRecordCount(dbfFile))
throw std::domain_error("dbf file has different entity count.");
for (int k = 0; k < entityCount; k++)
{
SHPObject* shape = SHPReadObject(shpFile, k);
if (shape == NULL)
throw std::domain_error("Unable to read shape:" + to_string(k));
Tags tags = parseTags(dbfFile, k);
visitShape(*shape, tags, visitor);
SHPDestroyObject(shape);
}
DBFClose(dbfFile);
SHPClose(shpFile);
}
示例6: SHPGetInfo
// ---------------------------------------------------------------------------
//
// -----------
SHPObject* bSHPTable::vxs2shape(int o, ivertices* vxs){
int count;
int ptype;
double bmin[4],bmax[4];
SHPObject* obj;
SHPGetInfo(_shp,&count,&ptype,bmin,bmax);
if(ptype==SHPT_NULL){
obj=SHPCreateSimpleObject(ptype,0,NULL,NULL,NULL);
}
else{
double* x=(double*)malloc(ivs_n_vxs(vxs)*sizeof(double));
double* y=(double*)malloc(ivs_n_vxs(vxs)*sizeof(double));
int np=(ivs_n_parts(vxs)>1)?ivs_n_parts(vxs):0;
int* p=(ivs_n_parts(vxs)>1)?(int*)malloc(ivs_n_parts(vxs)*sizeof(int)):NULL;
int* pt=(ivs_n_parts(vxs)>1)?(int*)malloc(ivs_n_parts(vxs)*sizeof(int)):NULL;
dvertices* dvxs=NULL;
vxs_i2d(&dvxs,vxs,_reso);
dvs_move(dvxs,_ox,_oy);
transform_a2t(dvxs);
if(p){
memmove(p,vxs->offs,vxs->no*sizeof(int));
memset(pt,SHPP_RING,vxs->no*sizeof(int));
}
for(int i=0;i<ivs_n_vxs(vxs);i++){
x[i]=dvxs->vx.vx2[i].x;
y[i]=dvxs->vx.vx2[i].y;
}
dvs_free(dvxs);
obj=SHPCreateObject(ptype,o-1,np,p,pt,ivs_n_vxs(vxs),x,y,NULL,NULL);
}
return(obj);
}
示例7: count_shape_points
int count_shape_points(char *shape_name)
{
int entidades;
SHPHandle arquivo_shp;
arquivo_shp=SHPOpen(shape_name, "r");
SHPGetInfo(arquivo_shp,&entidades,NULL,NULL,NULL);
return entidades;
}
示例8: readoutlets
// Function to read outlets from a shapefile - overloaded to return an array of integer ID's
int readoutlets(char *outletsfile, int *noutlets, double*& x, double*& y, int*& id)
{
SHPHandle shp = SHPOpen(outletsfile, "rb");
char dbffile[MAXLN];
nameadd(dbffile, outletsfile, ".dbf");
DBFHandle dbf = DBFOpen(dbffile, "rb");
if ((shp != NULL) && (dbf != 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;
int nfld = DBFGetFieldCount(dbf);
//int idfld = DBFGetFieldIndex(dbf, "id");
int idfld = DBFGetFieldIndex(dbf, "OBJECTID"); // ZhuLJ, 2015/6/16
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];
if (idfld >= 0)
id = new int[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];
if (idfld >= 0)
{
id[nxy] = DBFReadIntegerAttribute(dbf, i, idfld);
}
nxy++;
}
SHPDestroyObject(shape);
}
*noutlets=nxy;
SHPClose(shp);
return 0;
}
else {
fprintf(stderr, "Error opening outlets shapefile: %s\n", outletsfile);
fflush(stderr);
return 1;
}
}
示例9: return
// ---------------------------------------------------------------------------
//
// -----------
int bSHPTable::CountRecords(){
if(!_shp){
return(0);
}
int count;
int ptype;
double bmin[4],bmax[4];
SHPGetInfo(_shp,&count,&ptype,bmin,bmax);
return(count);
}
示例10: shape_load_globe
shapes_v
shape_load_globe(const char* filename) {
shapes_v globe;
kv_init(globe);
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
uint32_t parts = shp->nParts;
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);
}
kv_push(shape_v, globe, shape);
}
SHPDestroyObject( shp );
}
SHPClose( hSHP );
end_loading:
return globe;
}
示例11: shapelib_len
static int shapelib_len(lua_State *ls)
{
SHPHandle shp = checkshphandle(ls);
int entcount;
SHPGetInfo(shp, &entcount, 0, 0, 0);
lua_pushnumber(ls, entcount);
return 1;
}
示例12: shape_reader
shape_reader(std::string const& name)
{
m_shp = ::SHPOpen((name + ".shp").c_str(), "rb");
m_dbf = ::DBFOpen((name + ".dbf").c_str(), "rb");
if (m_shp == NULL || m_dbf == NULL)
{
throw shapelib_file_open_exception(name);
}
double adfMinBound[4], adfMaxBound[4];
SHPGetInfo(m_shp, &m_count, &m_shape_type, adfMinBound, adfMaxBound );
}
示例13: GetSHPType
int GetSHPType(const char *filename)
{
// SHPOpen doesn't yet support utf-8 or wide filenames, so convert
vtString fname_local = UTF8ToLocal(filename);
SHPHandle hSHP = SHPOpen(fname_local, "rb");
if (hSHP == NULL)
return SHPT_NULL;
int nEntities, nShapeType;
SHPGetInfo(hSHP, &nEntities, &nShapeType, NULL, NULL);
SHPClose(hSHP);
return nShapeType;
}
示例14: _bTrace_
// ---------------------------------------------------------------------------
// Constructeur
// ------------
bSHPTable ::bSHPTable( const char* path,
const char* name,
bool create,
double* reso,
double* ox,
double* oy,
int* tsrid,
int* asrid,
int* status)
:bStdTable(*reso,*ox,*oy,*tsrid,*asrid,status){
_bTrace_("bSHPTable::bSHPTable",false);
int ptype=db2shp(*status);
char fpath[1024];
sprintf(fpath,"%s%s",path,name);
//_tm_(fpath);
_shp=SHPOpen(fpath,"rb+");
if(!_shp){
//_te_("SHPOpen failed for rb+");
_shp=SHPOpen(fpath,"rb");
}
//_tm_("SHPOpen passed");
if(_shp){
int count;
double bmin[4],bmax[4];
//_tm_("SHPGetInfo");
SHPGetInfo(_shp,&count,&ptype,bmin,bmax);
//_tm_(count+" objects of "+ptype+" kind");
*status=shp2db(ptype);
return;
}
//_te_("SHPOpen failed for rb");
if(!create){
*status=-1;
_te_(fpath+" : table not found");
return;
}
_shp=SHPCreate(fpath,ptype);
if(!_shp){
_te_(fpath+" : creation failed");
*status=-1;
return;
}
*status=0;
}
示例15: 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);
}