cvs: pecl /shp shp.c /shp/tests 001.phpt

From: Date: Mon, 11 Apr 2005 20:06:49 +0000
Subject: cvs: pecl /shp shp.c /shp/tests 001.phpt
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-2971@lists.php.net to get a copy of this message
andrey Mon Apr 11 16:06:49 2005 EDT Modified files: /pecl/shp shp.c /pecl/shp/tests 001.phpt Log: - shp_get_info() implemented - prototypes fixed - add test cases for shp_get_info()

http://cvs.php.net/diff.php/pecl/shp/shp.c?r1=1.3&r2=1.4&ty=u Index: pecl/shp/shp.c diff -u pecl/shp/shp.c:1.3 pecl/shp/shp.c:1.4 --- pecl/shp/shp.c:1.3 Sun Apr 10 14:13:12 2005 +++ pecl/shp/shp.c Mon Apr 11 16:06:47 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: shp.c,v 1.3 2005/04/10 18:13:12 andrey Exp $ */ +/* $Id: shp.c,v 1.4 2005/04/11 20:06:47 andrey Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -92,7 +92,7 @@ /* shp_open - implemented -shp_get_info - NOT implemented +shp_get_info - implemented shp_read_object - implemented shp_close - implemented shp_create - implemented @@ -105,8 +105,7 @@ */ - -/* {{{ proto string shp_open(string filename, string access) +/* {{{ proto resource shp_open(string filename, string access) Opens a SHP handle */ PHP_FUNCTION(shp_open) { @@ -128,7 +127,7 @@ } /* }}} */ -/* {{{ proto string shp_create(string filename, string access) +/* {{{ proto resource shp_create(string filename, string access) Creates a SHP handle */ PHP_FUNCTION(shp_create) { @@ -161,7 +160,7 @@ /* }}} */ -/* {{{ proto string shp_close(resource shp) +/* {{{ proto bool shp_close(resource shp) Close a SHP handle */ PHP_FUNCTION(shp_close) { @@ -179,9 +178,6 @@ } ZEND_FETCH_RESOURCE(shph, SHPHandle, &res, c_id, SHPHANDLE_RES_NAME, le_shphandle); - if (!shph) { - RETURN_FALSE; - } zend_list_delete(Z_LVAL_P(res)); ZVAL_NULL(res); @@ -189,7 +185,7 @@ } /* }}} */ -/* {{{ proto string shp_read_object(resource shp, int ord) +/* {{{ proto resource shp_read_object(resource shp, int ord) Reads an object from a handle. The numbering starts from 0 */ PHP_FUNCTION(shp_read_object) { @@ -209,10 +205,6 @@ } ZEND_FETCH_RESOURCE(shph, SHPHandle, &res, c_id, SHPHANDLE_RES_NAME, le_shphandle); - if (!shph) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got NULL from the resource"); - RETURN_FALSE; - } shp_obj = SHPReadObject(shph, ord); if (!shp_obj) { @@ -225,7 +217,7 @@ /* }}} */ -/* {{{ proto string shp_destroy_object(resource shp_object) +/* {{{ proto bool shp_destroy_object(resource shp_object) This function should be used to deallocate the resources associated with a SHPObject when it is no longer needed, including those created with shp_create_simple_object(), shp_create_object() and returned from shp_read_object(). */ PHP_FUNCTION(shp_destroy_object) { @@ -243,9 +235,6 @@ } ZEND_FETCH_RESOURCE(shp_obj, SHPObject *, &res, c_id, SHPOBJECT_RES_NAME, le_shpobject); - if (!shp_obj) { - RETURN_FALSE; - } zend_list_delete(Z_LVAL_P(res)); ZVAL_NULL(res); @@ -254,7 +243,7 @@ } /* }}} */ -/* {{{ proto string shp_rewind_object(resource shp_handle, resource shp_object) +/* {{{ proto bool shp_rewind_object(resource shp_handle, resource shp_object) This function will reverse any rings necessary in order to enforce the shapefile restrictions on the required order of inner and outer rings in the Shapefile specification. It returns TRUE if a change is made and FALSE if no change is made. Only polygon objects will be affected though any object may be passed. */ PHP_FUNCTION(shp_rewind_object) { @@ -274,15 +263,12 @@ ZEND_FETCH_RESOURCE(shph, SHPHandle, &res_handle, c_id, SHPHANDLE_RES_NAME, le_shphandle); ZEND_FETCH_RESOURCE(shp_obj, SHPObject *, &res_obj, c_id, SHPOBJECT_RES_NAME, le_shpobject); - if (!shp_obj) { - RETURN_FALSE; - } RETURN_BOOL(SHPRewindObject(shph, shp_obj)); } /* }}} */ -/* {{{ proto string shp_write_object(resource shp_handle, resource shp_object) +/* {{{ proto int shp_write_object(resource shp_handle, int entity_num, resource shp_object) The shp_write_object() call is used to write a single structure, or entity to the shapefile. See the definition of the SHPObject structure for detailed information on fields of a SHPObject. The return value is the entity number of the written shape. */ PHP_FUNCTION(shp_write_object) { @@ -309,6 +295,47 @@ /* }}} */ +/* {{{ proto mixed shp_get_info(resource shp_handle) + Retrieves various information about shapefile as a whole. The bounds are read from the file header, and may be inaccurate if the file was improperly generated.*/ +PHP_FUNCTION(shp_get_info) +{ + zval *res; + SHPHandle shph; + int c_id = -1; + int i = 0; + zval *min_bound, *max_bound; + double min_b[4], max_b[4]; + int ent_n, shp_type; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { + RETURN_FALSE; + } + + if (!res) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got NULL for res"); + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE(shph, SHPHandle, &res, c_id, SHPHANDLE_RES_NAME, le_shphandle); + SHPGetInfo(shph, &ent_n, &shp_type, min_b, max_b); + MAKE_STD_ZVAL(min_bound); + MAKE_STD_ZVAL(max_bound); + array_init(min_bound); + array_init(max_bound); + SHPGetInfo(shph, &ent_n, &shp_type, min_b, max_b); + for (i = 0; i < 4; ++i) { + add_next_index_double(min_bound, min_b[i]); + add_next_index_double(max_bound, max_b[i]); + } + array_init(return_value); + add_assoc_long_ex(return_value, "pnEntities", sizeof("pnEntities"), ent_n); + add_assoc_long_ex(return_value, "pnShapetype", sizeof("pnShapetype"), shp_type); + add_assoc_zval_ex(return_value, "padfMinBound", sizeof("padfMinBound"), min_bound); + add_assoc_zval_ex(return_value, "padfMaxBound", sizeof("padfMaxBound"), max_bound); +} +/* }}} */ + + /* {{{ shp_functions[] * * Every user visible function must have an entry in shp_functions[]. @@ -321,6 +348,7 @@ PHP_FE(shp_destroy_object, NULL) PHP_FE(shp_rewind_object, NULL) PHP_FE(shp_write_object, NULL) + PHP_FE(shp_get_info, NULL) {NULL, NULL, NULL} /* Must be the last line in shp_functions[] */ }; /* }}} */ http://cvs.php.net/diff.php/pecl/shp/tests/001.phpt?r1=1.1&r2=1.2&ty=u Index: pecl/shp/tests/001.phpt diff -u pecl/shp/tests/001.phpt:1.1 pecl/shp/tests/001.phpt:1.2 --- pecl/shp/tests/001.phpt:1.1 Sun Apr 10 13:24:23 2005 +++ pecl/shp/tests/001.phpt Mon Apr 11 16:06:48 2005 @@ -2,10 +2,9 @@ Check for shp presence --FILE-- <?php -//--SKIPIF-- -//< ?php if (!extension_loaded("shp") || !dl('build/shp.so')) print "skip"; ? > +error_reporting(E_ALL & ~E_STRICT); +//if (!extension_loaded('shp')) dl('/home/andrey/dev/5_1/php-src/ext/shp/modules/shp.so'); -error_reporting(E_ALL); echo "Opening a file with rb+: "; $shph = shp_open("/tmp/lakes.shp", "rb"); @@ -61,12 +60,26 @@ var_dump($res); unlink('/tmp/lakes_for_update.shp'); unlink('/tmp/lakes_for_update.shx'); -echo "\n-END-\n"; +echo "Opening empty file (/tmp/tmp.shp): "; +$shph = shp_open("/tmp/temp.shp", "rb"); +var_dump($shph); + +$res = shp_get_info($shph); +var_dump($res); +shp_close($shph); + +echo "Opening empty /tmp/lakes.shp: "; +$shph = shp_open("/tmp/lakes.shp", "rb"); +var_dump($shph); + +$res = shp_get_info($shph); +var_dump($res); +shp_close($shph); +echo "\n-END-\n"; ?> --EXPECTF-- -Strict Standards: dl() is deprecated - use extension=%s.so in your php.ini in %s on line %d Opening a file with rb+: resource(%d) of type (SHP Handle) Closing a file: bool(true) Creating a file: resource(%d) of type (SHP Handle) @@ -84,5 +97,63 @@ Extracting object 2: resource(%d) of type (SHP Object) Now writing at the end (no error): int(3) Now closing the file: bool(true) +Opening empty file (/tmp/tmp.shp): resource(14) of type (SHP Handle) +array(4) { + ["pnEntities"]=> + int(0) + ["pnShapetype"]=> + int(1) + ["padfMinBound"]=> + array(4) { + [0]=> + float(0) + [1]=> + float(0) + [2]=> + float(0) + [3]=> + float(0) + } + ["padfMaxBound"]=> + array(4) { + [0]=> + float(0) + [1]=> + float(0) + [2]=> + float(0) + [3]=> + float(0) + } +} +Opening empty /tmp/lakes.shp: resource(15) of type (SHP Handle) +array(4) { + ["pnEntities"]=> + int(3) + ["pnShapetype"]=> + int(5) + ["padfMinBound"]=> + array(4) { + [0]=> + float(-103.42584%s) + [1]=> + float(18.09277%s) + [2]=> + float(-1.6125%s) + [3]=> + float(0) + } + ["padfMaxBound"]=> + array(4) { + [0]=> + float(-96.35890%s) + [1]=> + float(20.339996%s) + [2]=> + float(0) + [3]=> + float(0) + } +} -END-
« previous php.pecl.cvs (#2971) next »