Giter VIP home page Giter VIP logo

Comments (4)

controversial avatar controversial commented on August 17, 2024

I like this idea. Can't you change the dim parameter though?

from api-docs.

isaachinman avatar isaachinman commented on August 17, 2024

@The-Penultimate-Defenestrator

Hey there, it's been quite awhile since I've used the API. From what I recall, the image files themselves are a set size (delivered straight from the satellite), so any stitching or compiled tiles would have to be an additional feature.

from api-docs.

controversial avatar controversial commented on August 17, 2024

There is a dim argument, described as:

width and height of the image in degrees

And the default is 0.025

from api-docs.

controversial avatar controversial commented on August 17, 2024

My Python stitching code:

import urllib2
import json
import time
from io import BytesIO
from PIL import Image

URL="https://api.nasa.gov/planetary/earth/imagery?lon={}&lat={}&date={}&api_key={}"
API_KEY="ymjXp9qz2jJDR5tNEb0qa5YekynvAcVLJvKVcxYH"

def get_satellite_image(location=None,date=None):
    if location is None:
        location=(41.7475067,-74.0968971) #Coordinates of New Paltz
    if date is None:
        date=time.strftime("%Y-%m-%d")

    lat,lon=location

    req_url=URL.format(str(lon),str(lat),date,API_KEY)
    req=json.loads(urllib2.urlopen(req_url).read())

    image_url=req["url"]
    print "Image at "+image_url
    image = urllib2.urlopen(image_url)
    b=BytesIO(image.read())
    return b

def get_stitched_satellite_image(l=(41.7475067,-74.0968971),date=None):
    d=0.025
    coords = [l,#Original
                (l[0]+d,l[1]),(l[0],l[1]+d),(l[0]-d,l[1]),(l[0],l[1]-d),#Horizontally adjacent
                (l[0]+d,l[1]+d),(l[0]+d,l[1]-d),(l[0]-d,l[1]-d),(l[0]-d,l[1]+d)]#Diagonally adjacent

    coords.sort()
    image_files=[get_satellite_image(c,date) for c in coords]
    images=[Image.open(i) for i in image_files]
    imsize=512

    canvas=Image.new('RGB',(imsize*3,imsize*3))
    index=0
    for y in range(2,-1,-1):
        for x in range(3):
            coords=(x*imsize,y*imsize)
            canvas.paste(images[index],coords)
            index+=1        
    return canvas

def save_satellite_image(location=None,date=None,filename='out.png'):
    Image.open(get_satellite_image(location,date)).save(filename)

def save_stitched_satellite_image(location=(41.7475067,-74.0968971),date=None,filename='out.png'):
    get_stitched_satellite_image(location,date).save(filename)

if __name__ == "__main__":
    save_stitched_satellite_image((40.7,-74.0))

from api-docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.