Skip to content

Commit

Permalink
load vertices - ignoring parts
Browse files Browse the repository at this point in the history
  • Loading branch information
richardemslie committed Apr 27, 2013
1 parent 04754c3 commit fbaea10
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bindings/shapefilehandle.cc
Expand Up @@ -84,7 +84,7 @@ void async_open_after(uv_work_t * request, int) {
if (try_catch.HasCaught())
FatalException(try_catch);

printf("free() resources");
//printf("free() resources");

};

Expand Down
53 changes: 51 additions & 2 deletions bindings/shapeobject.cc
Expand Up @@ -32,6 +32,27 @@ Local<Object> ShapeObject::getObject() {

);

jsShape->Set(

String::NewSymbol("type"),
Number::New(shape->nSHPType)

);

jsShape->Set(

String::NewSymbol("partCount"),
Number::New(shape->nParts)

);

jsShape->Set(

String::NewSymbol("vertexCount"),
Number::New(shape->nVertices)

);

jsShape->Set(

String::NewSymbol("fields"),
Expand All @@ -41,7 +62,7 @@ Local<Object> ShapeObject::getObject() {

jsShape->Set(

String::NewSymbol("parts"),
String::NewSymbol("vertices"),
getParts()

);
Expand All @@ -55,7 +76,35 @@ Local<Array> ShapeObject::getParts() {

HandleScope scope;

return scope.Close( Array::New() );
// Local<Array> parts = Array::New();

//
// i'm confuzed about how to read the parts,
// so only supporting first part
//
// or that's what i think i'm doing,
// docs a bit vague on the meaning of part
//

Local<Array> vertices = Array::New();

int i;
for(i = 0; i < shape->nVertices; i++ ) {

Local<Array> vertex = Array::New();

vertex->Set(Number::New(0), Number::New(shape->padfX[i]));
vertex->Set(Number::New(1), Number::New(shape->padfY[i]));
vertex->Set(Number::New(2), Number::New(shape->padfZ[i]));
vertex->Set(Number::New(3), Number::New(shape->padfM[i]));

vertices->Set(i, vertex);

}

//parts->Set(Number::New(0), vertices);

return scope.Close(vertices);

};

Expand Down
4 changes: 2 additions & 2 deletions test.coffee
Expand Up @@ -13,9 +13,9 @@ shapeFile.open './deps/huh/ne_110m_land', (err, shapeData) ->
# data: shapeData

for i in [0..shapeData.count-1]

console.log shapeData.shapes[i]
console.log shapeData.shapes[i].vertices

#console.log shapeData.shapes[126].vertices
#shapeHandle.close()
#shapeHandle.openSync
#shapeHandle.readObjectSync

0 comments on commit fbaea10

Please sign in to comment.