Exemplo n.º 1
0
Handle<Value> Geometry::exportToWKB(const Arguments& args)
{
	HandleScope scope;

	Geometry *geom = ObjectWrap::Unwrap<Geometry>(args.This());
	
	int size = geom->this_->WkbSize();
	unsigned char *data = (unsigned char*) malloc(size);
	
	//byte order 
	OGRwkbByteOrder byte_order;
	std::string order = "MSB";
	NODE_ARG_OPT_STR(0, "byte order", order);
	if (order == "MSB") {
		byte_order = wkbXDR;
	} else if (order == "LSB") {
		byte_order = wkbNDR;
	} else {
		return NODE_THROW("byte order must be 'MSB' or 'LSB'");
	}

	#if GDAL_VERSION_NUM > 1100000 
	//wkb variant
	OGRwkbVariant wkb_variant;
	std::string variant = "OGC";
	NODE_ARG_OPT_STR(1, "wkb variant", variant);
	if (variant == "OGC") {
		wkb_variant = wkbVariantOgc;
	} else if (order == "ISO") {
		wkb_variant = wkbVariantIso;
	} else {
		return NODE_THROW("byte order must be 'OGC' or 'ISO'");
	}
	OGRErr err = geom->this_->exportToWkb(byte_order, data, wkb_variant);
	#else
	OGRErr err = geom->this_->exportToWkb(byte_order, data);
	#endif

	//^^ export to wkb and fill buffer ^^
	//TODO: avoid extra memcpy in FastBuffer::New and have exportToWkb write directly into buffer

	if (err) {
		free(data);
		return NODE_THROW_OGRERR(err);
	}

	Handle<Value> result = FastBuffer::New(data, size);
	free(data);

	return scope.Close(result);
	
}
Exemplo n.º 2
0
Handle<Value> Dataset::setGCPs(const Arguments& args)
{
	Dataset *ds = ObjectWrap::Unwrap<Dataset>(args.This());
	if(!ds->this_) return NODE_THROW("Dataset object has already been destroyed");

	Handle<Array> gcps;
	std::string projection("");
	NODE_ARG_ARRAY(0, "gcps", gcps);
	NODE_ARG_OPT_STR(1, "projection", projection);

	GDAL_GCP* list = new GDAL_GCP [gcps->Length()];
	GDAL_GCP* gcp = list;
	for (unsigned int i = 0; i < gcps->Length(); ++i) {
		Local<Value> val = gcps->Get(i);
		if (!val->IsObject()) {
			return NODE_THROW("list of GCPs must only contain objects");
		}
		Local<Object> obj = val->ToObject();

		NODE_STR_FROM_OBJ_OPT(obj, "pszId", gcp->pszId);
		NODE_STR_FROM_OBJ_OPT(obj, "pszInfo", gcp->pszInfo);
		NODE_DOUBLE_FROM_OBJ(obj, "dfGCPPixel", gcp->dfGCPPixel);
		NODE_DOUBLE_FROM_OBJ(obj, "dfGCPLine", gcp->dfGCPLine);
		NODE_DOUBLE_FROM_OBJ(obj, "dfGCPX", gcp->dfGCPX);
		NODE_DOUBLE_FROM_OBJ(obj, "dfGCPY", gcp->dfGCPY);
		NODE_DOUBLE_FROM_OBJ_OPT(obj, "dfGCPZ", gcp->dfGCPZ);
		gcp++;
	}

	if (list) delete [] list;

	CPLErr err = ds->this_->SetGCPs(gcps->Length(), list, projection.c_str());
	if(err) return NODE_THROW_CPLERR(err);

	return Undefined();
}