Skip to main content

A couple of ways you can solve this: you could switch out your geometry field for a geography fielda geography field within GeoDjango, then any native area calls should return values in meters which can easily be converted to the units you're interested in.

If you want to stick to storing things in geographic space as plain geometries, then you'll need to do conversion somewhere: you can't calculate area from geographic coordinates. You could instead add a helper method which is in a projected coordinate space to do the transformation:

def get_acres(self): 
    """ 
    Returns the area in acres. 
    """ 
    # Convert our geographic polygons (in WGS84)
    # into a local projection for New York (here EPSG:32118) 
    self.polygon.transform(32118) 
    meters_sq = self.polygon.area.sq_m
    
    acres = meters_sq * 0.000247105381  # meters^2 to acres

    return acres

Which projection you should use depends on the extent of the data, and how accurate you need the results: here I've illustrated with a specific projection for part of New York, but if your data isn't particularly accurate, you could easily substitute a global projection or just use a simple formula as @whuber mentioned in his comment.

A couple of ways you can solve this: you could switch out your geometry field for a geography field within GeoDjango, then any native area calls should return values in meters which can easily be converted to the units you're interested in.

If you want to stick to storing things in geographic space as plain geometries, then you'll need to do conversion somewhere: you can't calculate area from geographic coordinates. You could instead add a helper method which is in a projected coordinate space to do the transformation:

def get_acres(self): 
    """ 
    Returns the area in acres. 
    """ 
    # Convert our geographic polygons (in WGS84)
    # into a local projection for New York (here EPSG:32118) 
    self.polygon.transform(32118) 
    meters_sq = self.polygon.area.sq_m
    
    acres = meters_sq * 0.000247105381 # meters^2 to acres

    return acres

Which projection you should use depends on the extent of the data, and how accurate you need the results: here I've illustrated with a specific projection for part of New York, but if your data isn't particularly accurate, you could easily substitute a global projection or just use a simple formula as @whuber mentioned in his comment.

A couple of ways you can solve this: you could switch out your geometry field for a geography field within GeoDjango, then any native area calls should return values in meters which can easily be converted to the units you're interested in.

If you want to stick to storing things in geographic space as plain geometries, then you'll need to do conversion somewhere: you can't calculate area from geographic coordinates. You could instead add a helper method which is in a projected coordinate space to do the transformation:

def get_acres(self): 
    """ 
    Returns the area in acres. 
    """ 
    # Convert our geographic polygons (in WGS84)
    # into a local projection for New York (here EPSG:32118)
    self.polygon.transform(32118)
    meters_sq = self.polygon.area
    
    acres = meters_sq * 0.000247105381  # meters^2 to acres

    return acres

Which projection you should use depends on the extent of the data and how accurate you need the results: here I've illustrated with a specific projection for part of New York, but if your data isn't particularly accurate, you could easily substitute a global projection or just use a simple formula as @whuber mentioned in his comment.

added 4 characters in body
Source Link
scw
  • 16.4k
  • 6
  • 65
  • 101

A couple of ways you can solve this: you could switch out your geometry field for a geography field within GeoDjango, then any native area calls should return values in meters which can easily be converted to the units you're interested in.

If you want to stick to storing things in geographic space as plain geometries, then you'll need to do conversion somewhere: you can't calculate area from geographic coordinates. You could instead add a helper method which is in a projected coordinate space to do the transformation:

def get_acres(self): 
    """ 
    Returns the area in acres. 
    """ 
    # Convert our geographic polygons (in WGS84)
    # into a local projection for New York (here EPSG:32118) 
    self.polygon.transform(32118) 
    meters_sq = self.polygon.area .sq_m
    
    acres = meters_sq * 0.000247105381 # meters^2 to acres

    return acres

Which projection you should use depends on the extent of the data, and how accurate you need the results: here I've illustrated with a specific projection for part of New York, but if your data isn't particularly accurate, you could easily substitute a global projection or just use a simple formula as @whuber mentioned in his comment.

A couple of ways you can solve this: you could switch out your geometry field for a geography field within GeoDjango, then any native area calls should return values in meters which can easily be converted to the units you're interested in.

If you want to stick to storing things in geographic space as plain geometries, then you'll need to do conversion somewhere: you can't calculate area from geographic coordinates. You could instead add a helper method which is in a projected coordinate space to do the transformation:

def get_acres(self): 
    """ 
    Returns the area in acres. 
    """ 
    # Convert our geographic polygons (in WGS84)
    # into a local projection for New York (here EPSG:32118) 
    self.polygon.transform(32118) 
    meters_sq = self.polygon.area 
    
    acres = meters_sq * 0.000247105381 # meters^2 to acres

    return acres

Which projection you should use depends on the extent of the data, and how accurate you need the results: here I've illustrated with a specific projection for part of New York, but if your data isn't particularly accurate, you could easily substitute a global projection or just use a simple formula as @whuber mentioned in his comment.

A couple of ways you can solve this: you could switch out your geometry field for a geography field within GeoDjango, then any native area calls should return values in meters which can easily be converted to the units you're interested in.

If you want to stick to storing things in geographic space as plain geometries, then you'll need to do conversion somewhere: you can't calculate area from geographic coordinates. You could instead add a helper method which is in a projected coordinate space to do the transformation:

def get_acres(self): 
    """ 
    Returns the area in acres. 
    """ 
    # Convert our geographic polygons (in WGS84)
    # into a local projection for New York (here EPSG:32118) 
    self.polygon.transform(32118) 
    meters_sq = self.polygon.area.sq_m
    
    acres = meters_sq * 0.000247105381 # meters^2 to acres

    return acres

Which projection you should use depends on the extent of the data, and how accurate you need the results: here I've illustrated with a specific projection for part of New York, but if your data isn't particularly accurate, you could easily substitute a global projection or just use a simple formula as @whuber mentioned in his comment.

Source Link
scw
  • 16.4k
  • 6
  • 65
  • 101

A couple of ways you can solve this: you could switch out your geometry field for a geography field within GeoDjango, then any native area calls should return values in meters which can easily be converted to the units you're interested in.

If you want to stick to storing things in geographic space as plain geometries, then you'll need to do conversion somewhere: you can't calculate area from geographic coordinates. You could instead add a helper method which is in a projected coordinate space to do the transformation:

def get_acres(self): 
    """ 
    Returns the area in acres. 
    """ 
    # Convert our geographic polygons (in WGS84)
    # into a local projection for New York (here EPSG:32118) 
    self.polygon.transform(32118) 
    meters_sq = self.polygon.area 
    
    acres = meters_sq * 0.000247105381 # meters^2 to acres

    return acres

Which projection you should use depends on the extent of the data, and how accurate you need the results: here I've illustrated with a specific projection for part of New York, but if your data isn't particularly accurate, you could easily substitute a global projection or just use a simple formula as @whuber mentioned in his comment.