Forum

Author Topic: Getting wgs84 coordinates of a face's vertices  (Read 7560 times)

HenriPierre

  • Newbie
  • *
  • Posts: 13
    • View Profile
Getting wgs84 coordinates of a face's vertices
« on: October 26, 2012, 02:35:13 PM »
Hello

I'm trying to get the wgs84 coordinates of a face's vertices.
Preamble : I use a model that has been georeferenced using WGS84 GCPS.

Here's what I did :

Code: [Select]
doc = PhotoScan.app.document
chunk = doc.chunks[0]
model = chunk.models[0]
faces = model.faces

crs = PhotoScan.CoordinateSystem()
crs.init("EPSG::4326")

for face in faces:
    if face.selected:
        vertex = face.vertices[0]
        unpro = crs.unproject(model.vertices[vertex].coord)
        print (unpro)

Definitly, this does not provide a wgs84 coordinate.
What did I do wrong ?

Regards
Henri

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14965
    • View Profile
Re: Getting wgs84 coordinates of a face's vertices
« Reply #1 on: October 30, 2012, 06:54:35 PM »
Hello Henri,

For WGS84 the script should look like the following:

Code: [Select]
chunk = doc.chunks[0]
model = chunk.models[0]
faces = model.faces

crs = PhotoScan.CoordinateSystem()
crs.init("EPSG::4326")

for face in faces:
    if face.selected:
        vertex = face.vertices[0]
        v = vertex.coord
        v.size = 4
        v[3] = 1
        v_t = chunk.transform * v
        v_t = v_t / v[3]
        v_t.size = 3
        v_pro = crs.project(v_t)
        print (v_pro)
Best regards,
Alexey Pasumansky,
Agisoft LLC

HenriPierre

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Getting wgs84 coordinates of a face's vertices
« Reply #2 on: November 02, 2012, 01:05:34 PM »
Hello Alexey

Code: [Select]
    v = vertex.coord
AttributeError: 'int' object has no attribute 'coord'

Photoscan 0.9.

Henri

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14965
    • View Profile
Re: Getting wgs84 coordinates of a face's vertices
« Reply #3 on: November 02, 2012, 01:40:24 PM »
Hello Henri,

Instead of
Code: [Select]
v = vertex.coord there should go
Code: [Select]
v = model.vertices[vertex].coord
but this script will print only the first of three vertex coordinates for each selected face.
Best regards,
Alexey Pasumansky,
Agisoft LLC

HenriPierre

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Getting wgs84 coordinates of a face's vertices
« Reply #4 on: November 02, 2012, 05:35:57 PM »
Thanks

This works perfectly.

Hum, now I would like to do the inverse operation (wgs84 -> local coordinates)... ?