A C library for reading ESRI shapefiles. The shapefile format is a geospatial vector data format for geographic information system software.
The library supports the shp, shx and dbf formats.
DEPENDENCIES
Requires a C compiler that supports the C99 standard and CMake.
INSTALLATION
Run the following commands to install the library:
mkdir build
cd build
cmake ..
make
make test
make install
See Makefile.PL for information on how to add the library to a Perl XS module.
EXAMPLES
char *s;
double d;
if (s != NULL) {
puts(s);
free(s);
}
break;
printf("%lf\n", d);
}
break;
}
}
int read_dbf(const char *filename) {
int rc = -1;
FILE *stream;
stream = fopen(filename, "rb");
if (stream != NULL) {
while (field != NULL) {
print_field(record, field);
}
}
free(record);
}
free(header);
}
if (rc < 0) {
fprintf(stderr,
"%s\n", fh.
error);
}
fclose(stream);
}
return rc;
}
double x, y;
printf("[%lf, %lf]\n", x, y);
break;
}
}
int read_shp(const char *filename) {
int rc = -1;
FILE *stream;
stream = fopen(filename, "rb");
if (stream != NULL) {
print_shape(record);
free(record);
}
}
if (rc < 0) {
fprintf(stderr,
"%s\n", fh.
error);
}
fclose(stream);
}
return rc;
}
int main(int argc, char *argv[]) {
read_dbf("file.dbf");
read_shp("file.shp");
return 0;
}
@ DBF_TYPE_CHARACTER
String.
Definition: dbf.h:69
@ DBF_TYPE_NUMBER
Number (stored as a string)
Definition: dbf.h:91
@ DBF_TYPE_FLOAT
Number (stored as a string)
Definition: dbf.h:79
dbf_file_t * dbf_init_file(dbf_file_t *fh, FILE *stream, void *user_data)
Initialize a file handle.
Definition: dbf.c:55
int dbf_read_record(dbf_file_t *fh, dbf_record_t **precord)
Read a record.
Definition: dbf.c:1107
int dbf_read_header(dbf_file_t *fh, dbf_header_t **pheader)
Read the file header.
Definition: dbf.c:1060
int shp_read_header(shp_file_t *fh, shp_header_t *header)
Read the file header.
Definition: shp.c:87
int shp_read_record(shp_file_t *fh, shp_record_t **precord)
Read a record.
Definition: shp.c:849
@ SHP_TYPE_POINT
Point with X, Y coordinates.
Definition: shp.h:40
shp_file_t * shp_init_file(shp_file_t *fh, FILE *stream, void *user_data)
Initialize a file handle.
Definition: shp.c:56
Field.
Definition: dbf.h:105
struct dbf_field_t * next
Next field or NULL.
Definition: dbf.h:106
dbf_type_t type
Type.
Definition: dbf.h:108
File handle.
Definition: dbf.h:475
char error[128]
Error message.
Definition: dbf.h:491
Record.
Definition: dbf.h:135
int dbf_record_strtod(const dbf_record_t *record, const dbf_field_t *field, double *value)
Convert a string to double representation.
Definition: dbf.c:590
char * dbf_record_strdup(const dbf_record_t *record, const dbf_field_t *field)
Duplicate a string.
Definition: dbf.c:558
int dbf_record_is_deleted(const dbf_record_t *record)
Check if a record is deleted.
Definition: dbf.c:430
File handle.
Definition: shp.h:114
char error[128]
Error message.
Definition: shp.h:130
double x
X coordinate.
Definition: shp-point.h:25
double y
Y coordinate.
Definition: shp-point.h:26
Record.
Definition: shp.h:77
shp_point_t point
Point if type is SHP_TYPE_POINT.
Definition: shp.h:83
shp_type_t type
Shape type.
Definition: shp.h:80
LICENSE AND COPYRIGHT
Copyright (C) 2023 Andreas Vögele
This library is free software; you can redistribute it and/or modify it under either the terms of the ISC License or the same terms as Perl.