Example #1
0
Handle<Value> Dataset::setGeoTransform(const Arguments& args)
{
	Dataset *ds = ObjectWrap::Unwrap<Dataset>(args.This());
	if(!ds->this_) return NODE_THROW("Dataset object has already been destroyed");

	Handle<Array> transform;
	NODE_ARG_ARRAY(0, "transform", transform);

	if (transform->Length() != 6) {
		return NODE_THROW("Transform array must have 6 elements")
	}

	double buffer[6];
	for (int i = 0; i < 6; i++) {
		Local<Value> val = transform->Get(i);
		if (!val->IsNumber()) {
			return NODE_THROW("Transform array must only contain numbers");
		}
		buffer[i] = val->NumberValue();
	}

	CPLErr err = ds->this_->SetGeoTransform(buffer);
	if (err) return NODE_THROW_CPLERR(err);

	return Undefined();
}
Example #2
0
Handle<Value> LayerFields::reorder(const Arguments& args)
{
	HandleScope scope;

	Handle<Object> parent = args.This()->GetHiddenValue(String::NewSymbol("parent_"))->ToObject();
	Layer *layer = ObjectWrap::Unwrap<Layer>(parent);
	if (!layer->get()) {
		return NODE_THROW("Layer object already destroyed");
	}

	OGRFeatureDefn *def = layer->get()->GetLayerDefn();
	if (!def) {
		return NODE_THROW("Layer has no layer definition set");
	}

	Handle<Array> field_map = Array::New(0);
	NODE_ARG_ARRAY(0, "field map", field_map);

	int n = def->GetFieldCount();
	OGRErr err = 0;

	if ((int)field_map->Length() != n) {
		return NODE_THROW("Array length must match field count");
	}

	int *field_map_array = new int[n];

	for (int i = 0; i < n; i++) {
		Handle<Value> val = field_map->Get(i);
		if (!val->IsNumber()) {
			delete [] field_map_array;
			return NODE_THROW("Array must only contain integers");
		}

		int key = val->IntegerValue();
		if (key < 0 || key >= n) {
			delete [] field_map_array;
			return NODE_THROW("Values must be between 0 and field count - 1");
		}

		field_map_array[i] = key;
	}

	err = layer->get()->ReorderFields(field_map_array);

	delete [] field_map_array;

	if (err) {
		return NODE_THROW_OGRERR(err);
	}
	return Undefined();
}
Example #3
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();
}