def draw_tweets_detected(file):
    # Tweet info draw
    c = crs.Crs('EPSG:3857')
    # wms = WebMapService('http://www.ign.es/wms-inspire/pnoa-ma', version='1.3.0')

    box = 10000  # m?
    x = 238814  # m?
    y = 5069880  # m?
    picsize = 2048
    img1 = cv2.imread('fullmap.png')
    img_fields = cv2.imread('circle.png')
    overlay = img1.copy()
    tweets = img1.copy()
    final = img_fields.copy()
    with open(file, 'r') as csv_file:
        with open('locations.csv', 'r') as csv_locations:
            loc_reader = csv.reader(csv_locations)
            location_list = list(loc_reader)
            print(location_list)
            reader = csv.reader(csv_file, )
            reader.__next__()
            lat = []
            lon = []

            for row in reader:
                # print(format(row).encode())
                if location_is_near(row, location_list):
                    lat.append(row[2])
                    lon.append(row[3])

    print('Csv finished')
    n_tweets = len(lat)
    alpha = 2 / n_tweets
    colors, _ = color_palette(n_tweets)
    for i in range(len(lat[:n_tweets])):
        try:
            # print('Writing...{}'.format(i))
            proj = Proj(init='epsg:3857')
            xm, ym = proj(lon[i], lat[i])
            p1 = picsize / (2 * box) * (xm - (x - box))
            p2 = picsize / (2 * box) * ((y + box) - ym)
            # cv2.circle(overlay, (int(p1), int(p2)), 5, (int(colors[i][2] * 255), int(colors[i][1] * 255), int(colors[i][0] * 255)), -1)
            # cv2.circle(tweets, (int(p1), int(p2)), 5, (int(colors[i][2] * 255), int(colors[i][1] * 255), int(colors[i][0] * 255)), -1)
            cv2.circle(tweets, (int(p1), int(p2)), 5, (0, 200, 255), -1)
            cv2.circle(final, (int(p1), int(p2)), 5, (0, 200, 255), -1)

            # cv2.addWeighted(overlay, alpha,
            #                 tweets, 1 - alpha,
            #                 0, tweets)
        except Exception as e:
            print(e)

    cv2.imshow("Output", tweets)
    cv2.imwrite('tweets.png', tweets)
    cv2.imwrite('tweetsNfields.png', final)
Beispiel #2
0
def test_ows_bbox():
    bbox_elem = etree.fromstring("""
    <ows:BoundingBox xmlns:ows="{}" crs="EPSG:4326" dimensions="2">
        <ows:LowerCorner>0.0 -90.0</ows:LowerCorner>
        <ows:UpperCorner>180.0 90.0</ows:UpperCorner>
    </ows:BoundingBox>""".format(DEFAULT_OWS_NAMESPACE))
    bbox = BoundingBox(bbox_elem)
    assert bbox.crs == crs.Crs('EPSG:4326')
    assert bbox.crs.axisorder == 'yx'
    assert bbox.dimensions == 2
    assert bbox.minx == '-90.0'
    assert bbox.miny == '0.0'
    assert bbox.maxx == '90.0'
    assert bbox.maxy == '180.0'
Beispiel #3
0
def test_ows_bbox_with_namespaces():
    """ XML bounding box description as received from a wps request """

    bbox_elem = etree.fromstring("""
    <wps:BoundingBoxData xmlns:wps="{}" xmlns:ows="{}" ows:crs="EPSG:4326" ows:dimensions="2">
        <ows:LowerCorner>0.0 -90.0</ows:LowerCorner>
        <ows:UpperCorner>180.0 90.0</ows:UpperCorner>
    </wps:BoundingBoxData>""".format(DEFAULT_WPS_NAMESPACE,
                                     DEFAULT_OWS_NAMESPACE))
    bbox = BoundingBox(bbox_elem)
    assert bbox.crs == crs.Crs('EPSG:4326')
    assert bbox.crs.axisorder == 'yx'
    assert bbox.dimensions == 2
    assert bbox.minx == '-90.0'
    assert bbox.miny == '0.0'
    assert bbox.maxx == '90.0'
    assert bbox.maxy == '180.0'
Beispiel #4
0
    def __init__(self, element, nsmap):
        """initialize geometry parser"""

        self.nsmap = nsmap
        self.type = None
        self.wkt = None
        self.crs = None
        self._exml = element

        # return OGC WKT for GML geometry

        operand = element.xpath(
            '|'.join(TYPES), namespaces={'gml':
                                         'http://www.opengis.net/gml'})[0]

        if 'srsName' in operand.attrib:
            LOGGER.debug('geometry srsName detected')
            self.crs = crs.Crs(operand.attrib['srsName'])
        else:
            LOGGER.debug('setting default geometry srsName %s' % DEFAULT_SRS)
            self.crs = DEFAULT_SRS

        self.type = util.xmltag_split(operand.tag)

        if self.type == 'Point':
            self._get_point()
        elif self.type == 'LineString':
            self._get_linestring()
        elif self.type == 'Polygon':
            self._get_polygon()
        elif self.type == 'Envelope':
            self._get_envelope()
        else:
            raise RuntimeError(
                'Unsupported geometry type (Must be one of %s)' %
                ','.join(TYPES))

        # reproject data if needed
        if self.crs is not None and self.crs.code != 4326:
            LOGGER.debug('transforming geometry to 4326')
            try:
                self.wkt = self.transform(self.crs.code, DEFAULT_SRS.code)
            except Exception, err:
                raise RuntimeError('Reprojection error: Invalid srsName '
                                   '"%s": %s' % (self.crs.id, str(err)))
Beispiel #5
0
    def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE):
        self.minx = None
        self.miny = None
        self.maxx = None
        self.maxy = None
        self.crs = None
        self.dimensions = 2
        if elem is None:
            return
        val = elem.attrib.get('crs') or elem.attrib.get(
            '{{{}}}crs'.format(namespace))
        if val:
            try:
                self.crs = crs.Crs(val)
            except (AttributeError, ValueError):
                LOGGER.warning('Invalid CRS %r. Expected integer' % val)
        else:
            self.crs = None

        val = elem.attrib.get('dimensions') or elem.attrib.get(
            '{{{}}}dimensions'.format(namespace))
        if val is not None:
            self.dimensions = int(util.testXMLValue(val, True))
        else:  # assume 2
            self.dimensions = 2

        val = elem.find(util.nspath('LowerCorner', namespace))
        tmp = util.testXMLValue(val)
        if tmp is not None:
            xy = tmp.split()
            if len(xy) > 1:
                if self.crs is not None and self.crs.axisorder == 'yx':
                    self.minx, self.miny = xy[1], xy[0]
                else:
                    self.minx, self.miny = xy[0], xy[1]

        val = elem.find(util.nspath('UpperCorner', namespace))
        tmp = util.testXMLValue(val)
        if tmp is not None:
            xy = tmp.split()
            if len(xy) > 1:
                if self.crs is not None and self.crs.axisorder == 'yx':
                    self.maxx, self.maxy = xy[1], xy[0]
                else:
                    self.maxx, self.maxy = xy[0], xy[1]
Beispiel #6
0
    def __init__(self, element, nsmap):
        ''' initialize geometry parser  '''

        self.nsmap = nsmap
        self.type = None
        self.wkt = None
        self.crs = None
        self._exml = element
        ''' return OGC WKT for GML geometry '''

        operand = element.xpath(
            '|'.join(TYPES), namespaces={'gml':
                                         'http://www.opengis.net/gml'})[0]

        if operand.attrib.has_key('srsName'):
            self.crs = crs.Crs(operand.attrib['srsName'])
        else:
            self.crs = DEFAULT_SRS

        self.type = util.xmltag_split(operand.tag)

        if util.xmltag_split(operand.tag) == 'Point':
            self._get_point()
        elif util.xmltag_split(operand.tag) == 'LineString':
            self._get_linestring()
        elif util.xmltag_split(operand.tag) == 'Polygon':
            self._get_polygon()
        elif util.xmltag_split(operand.tag) == 'Envelope':
            self._get_envelope()
        else:
            raise RuntimeError, \
            ('Unsupported geometry type (Must be one of %s)' % ','.join(TYPES))

        # reproject data if needed
        if self.crs is not None and self.crs.code != 4326:
            try:
                self.wkt = self.transform(self.crs.code, DEFAULT_SRS.code)
            except Exception, err:
                raise RuntimeError, \
                ('Reprojection error: Invalid srsName "%s": %s' %
                (self.crs.id, str(err)))
def draw_fields_detected():
    c = crs.Crs('EPSG:3857')
    #wms = WebMapService('http://www.ign.es/wms-inspire/pnoa-ma', version='1.3.0')

    box = 10000  # m?
    x = 238814  #m?
    y = 5069880  #m?
    picsize = 2048
    """
    img = wms.getmap(
        layers=['OI.OrthoimageCoverage'],
        styles=[],
        srs='EPSG:3857',
        bbox=(x - box, y - box, x + box, y + box),
        size=(picsize,picsize), #W,H px
        format='image/png',
        transparent=False
    )
    with open('fullmap.png','wb') as out:
        out.write(img.read())
    """
    img1 = cv2.imread('fullmap.png')
    circles = img1.copy()

    xydict = getmap()
    for element in xydict.values():
        for value in element:
            lon = value[0]
            lat = value[1]
            try:
                proj = Proj(init='epsg:3857')
                xm, ym = proj(lon, lat)
                p1 = picsize / (2 * box) * (xm - (x - box))
                p2 = picsize / (2 * box) * ((y + box) - ym)
                cv2.circle(img1, (int(p1), int(p2)), 5, (0, 0, 255), -1)
                plt.imshow()
            except Exception as e:
                print(e)

    cv2.imwrite('circle.png', circles)
Beispiel #8
0
    def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE):
        self.minx = None
        self.miny = None
        self.maxx = None
        self.maxy = None

        val = elem.attrib.get('crs')
        if val is not None:
            self.crs = crs.Crs(val)
        else:
            self.crs = None

        val = elem.attrib.get('dimensions')
        if val is not None:
            self.dimensions = int(util.testXMLValue(val, True))
        else:  # assume 2
            self.dimensions = 2

        val = elem.find(util.nspath('LowerCorner', namespace))
        tmp = util.testXMLValue(val)
        if tmp is not None:
            xy = tmp.split()
            if len(xy) > 1:
                if self.crs is not None and self.crs.axisorder == 'yx':
                    self.minx, self.miny = xy[1], xy[0]
                else:
                    self.minx, self.miny = xy[0], xy[1]

        val = elem.find(util.nspath('UpperCorner', namespace))
        tmp = util.testXMLValue(val)
        if tmp is not None:
            xy = tmp.split()
            if len(xy) > 1:
                if self.crs is not None and self.crs.axisorder == 'yx':
                    self.maxx, self.maxy = xy[1], xy[0]
                else:
                    self.maxx, self.maxy = xy[0], xy[1]
Beispiel #9
0
 def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE):
     BoundingBox.__init__(self, elem, namespace)
     self.dimensions = 2
     self.crs = crs.Crs('urn:ogc:def:crs:OGC:2:84')
Beispiel #10
0
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# =================================================================

import logging
from pycsw import util
from owslib import crs

LOGGER = logging.getLogger(__name__)

TYPES = ['gml:Point', 'gml:LineString', 'gml:Polygon', 'gml:Envelope']

DEFAULT_SRS = crs.Crs('urn:x-ogc:def:crs:EPSG:6.11:4326')


def _poslist2wkt(poslist, axisorder):
    """Repurpose gml:posList into WKT aware list"""

    tmp = poslist.split()
    poslist2 = []

    xlist = tmp[1::2]
    ylist = tmp[::2]

    if axisorder == 'yx':
        for i, j in zip(ylist, xlist):
            poslist2.append('%s %s' % (i, j))
    else:
from owslib.wms import WebMapService
from owslib import crs
from PIL import Image, ImageEnhance, ImageFilter
import cv2
import numpy as np
from pyspark import SparkContext
from pyproj import Proj

c = crs.Crs('EPSG:3857')
wms = WebMapService('http://www.ign.es/wms-inspire/pnoa-ma', version='1.3.0')

box = 1000  # m?
x = 236814  #m?
y = 5068880  #m?
picsize = 512

img = wms.getmap(
    layers=['OI.OrthoimageCoverage'],
    styles=[],
    srs='EPSG:3857',
    bbox=(x - box, y - box, x + box, y + box),
    size=(picsize, picsize),  #W,H px
    format='image/png',
    transparent=False)
with open('image.png', 'wb') as out:
    out.write(img.read())


def green_detection():
    img = cv2.imread('image.png')
    # Green fields detection