The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Ushant Suman (23) [Avatar] Offline
Hi all,

I have a .shp file of some wells lat lon in WGS_84.When I created the map and gives it to the user user said that all the wells are not coming in the print of map.I am trying to found the way that to print the well names of all the four corners stored in the .dbf file in the same folder.I have written the script:

import os
import sys
from osgeo import ogr

t= f3.GetLayer(0)
print t.GetExtent()

This will print the bounding box{Minx,MIny,MaxX,MaXY] and return a python tuple but Is there any way to extend the script to print the wellname attribute along with X, Y of those corner wells stored in the .dbf file??
chris.garrard (26) [Avatar] Offline
Let me make sure I understand what you're asking. You want to find the most western, most eastern, most southern, and most northern well, and then print out their names and coordinates? If that's what you want, something like this would do it:

# Get extent
minx, maxx, miny, maxy = t.GetExtent()

# Put names and coordinates into three lists
name, x, y = zip(*[(row.GetField('well_name_field'), row.geometry().GetX(), row.geometry().GetY()) for row in lyr])

# Find the index of each bounding coordinate in the appropriate list and then print out info at that index from all three lists
i = x.index(minx)
print 'west', name[i], x[i], y[i]
i = x.index(maxx)
print 'east', name[i], x[i], y[i]
i = y.index(miny)
print 'south', name[i], x[i], y[i]
i = y.index(maxy)
print 'north', name[i], x[i], y[i]

Did that help, or did I misunderstand your question?
Ushant Suman (23) [Avatar] Offline
Thanks Chris for such a quick is exactly what I want to print.gr8.