コード例 #1
0
Datum gserialized_gist_consistent_2d(PG_FUNCTION_ARGS)
{
	GISTENTRY *entry = (GISTENTRY*) PG_GETARG_POINTER(0);
	StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
	bool result;
	BOX2DF query_gbox_index;

#if POSTGIS_PGSQL_VERSION >= 84
	/* PostgreSQL 8.4 and later require the RECHECK flag to be set here,
	   rather than being supplied as part of the operator class definition */
	bool *recheck = (bool *) PG_GETARG_POINTER(4);

	/* We set recheck to false to avoid repeatedly pulling every "possibly matched" geometry
	   out during index scans. For cases when the geometries are large, rechecking
	   can make things twice as slow. */
	*recheck = false;
#endif

	POSTGIS_DEBUG(4, "[GIST] 'consistent' function called");

	/* Quick sanity check on query argument. */
	if ( DatumGetPointer(PG_GETARG_DATUM(1)) == NULL )
	{
		POSTGIS_DEBUG(4, "[GIST] null query pointer (!?!), returning false");
		PG_RETURN_BOOL(FALSE); /* NULL query! This is screwy! */
	}

	/* Quick sanity check on entry key. */
	if ( DatumGetPointer(entry->key) == NULL )
	{
		POSTGIS_DEBUG(4, "[GIST] null index entry, returning false");
		PG_RETURN_BOOL(FALSE); /* NULL entry! */
	}

	/* Null box should never make this far. */
	if ( gserialized_datum_get_box2df_p(PG_GETARG_DATUM(1), &query_gbox_index) == LW_FAILURE )
	{
		POSTGIS_DEBUG(4, "[GIST] null query_gbox_index!");
		PG_RETURN_BOOL(FALSE);
	}

	/* Treat leaf node tests different from internal nodes */
	if (GIST_LEAF(entry))
	{
		result = gserialized_gist_consistent_leaf_2d(
		             (BOX2DF*)DatumGetPointer(entry->key),
		             &query_gbox_index, strategy);
	}
	else
	{
		result = gserialized_gist_consistent_internal_2d(
		             (BOX2DF*)DatumGetPointer(entry->key),
		             &query_gbox_index, strategy);
	}

	PG_RETURN_BOOL(result);
}
コード例 #2
0
Datum WTBtree_consistent(PG_FUNCTION_ARGS)
{	
	printf("------------------consistent\n");

	GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);	
	void	   *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
	StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
	bool		result;	
	/* Oid		subtype = PG_GETARG_OID(3); */
	
/*
GBT_VARKEY *orge = (GBT_VARKEY *) DatumGetPointer(entry->key);
GBT_VARKEY_R ok;

ok = gbt_var_key_readable(orge);

printf("ok.lower : %s\n", ok.lower);
printf("VARDATA(ok.lower) : %s\n", VARDATA(ok.lower));
printf("VARDATA(ok.upper) : %s\n", VARDATA(ok.upper));

printf("VARDATA_4B(ok.lower) : %s\n", VARDATA_4B(ok.lower));
printf("VARDATA_4B(ok.upper) : %s\n", VARDATA_4B(ok.upper));

*/
printf("strategy : %d\n", strategy);


char* temp;
temp = (char*) palloc(12);

memcpy(temp, "wx4fccknzng3", 12);

GeoCoord gCoord = geohash_decode(temp);

printf("gCoord.north : %lf\n", gCoord.north);
printf("gCoord.east : %lf\n", gCoord.east);
printf("gCoord.south : %lf\n", gCoord.south);
printf("gCoord.west : %lf\n", gCoord.west);

BOX2DF* tbox;
tbox = (BOX2DF*) palloc(sizeof(BOX2DF));

tbox->xmin = (float) gCoord.west;
tbox->ymin = (float) gCoord.south;
tbox->xmax = (float) gCoord.east;
tbox->ymax = (float) gCoord.north;


printf("temp : %s\n", temp);


BOX2DF query_gbox_index;
	gserialized_datum_get_box2df_p(query, &query_gbox_index);

	if (GIST_LEAF(entry))
	{
		result = gserialized_gist_consistent_leaf_2d(tbox,
		             &query_gbox_index, strategy);
	}
	else
	{
		result = gserialized_gist_consistent_internal_2d(tbox,
		             &query_gbox_index, strategy);
	}

/*
	BOX2DF query_gbox_index;
	gserialized_datum_get_box2df_p(query, &query_gbox_index);

	if (GIST_LEAF(entry))
	{
		result = gserialized_gist_consistent_leaf_2d(
		             (BOX2DF*)DatumGetPointer(entry->key),
		             &query_gbox_index, strategy);
	}
	else
	{
		result = gserialized_gist_consistent_internal_2d(
		             (BOX2DF*)DatumGetPointer(entry->key),
		             &query_gbox_index, strategy);
	}

*/

/*
	int size = 12;
	char *minPnt, *maxPnt, *cvtGeoHash;

	minPnt = (char*) palloc(size);
	maxPnt = (char*) palloc(size);
	cvtGeoHash = (char*) palloc(size);

	
	memcpy(minPnt, geohash_encode((double) query_gbox_index.ymin, (double) query_gbox_index.xmin, size), size);
	memcpy(maxPnt, geohash_encode((double) query_gbox_index.ymax, (double) query_gbox_index.xmax, size), size);

	cvtGeoHash = convert_GeoHash_from_box2d(minPnt, maxPnt, size);

	printf("-----------geohash_encode : %s\n", cvtGeoHash);	
*/
	/* PostgreSQL 8.4 and later require the RECHECK flag to be set here,
	   rather than being supplied as part of the operator class definition */

/*
	bool	   *recheck = (bool *) PG_GETARG_POINTER(4);

	LEAF_KEY key;

	memcpy(key, DatumGetPointer(entry->key), KEY_SIZE);

	INTERNAL_KEY *ikey = leafKey_to_internaKey(key);	


	*recheck = false;
*/	


	PG_RETURN_BOOL(result);
}