Skip to content

Instantly share code, notes, and snippets.

View BishopGIS's full-sized avatar

Dmitry Baryshnikov BishopGIS

  • NextGIS
  • Russia, Moscow
View GitHub Profile
@BishopGIS
BishopGIS / towgs.py
Last active March 1, 2023 17:38
Test to WGS84 accuracy
from osgeo import ogr, osr
pulkovo42v1 = osr.SpatialReference()
pulkovo42v1.ImportFromWkt("""GEOGCS["Pulkovo 1942 v2",
DATUM["Pulkovo_1942",
SPHEROID["Krassowsky 1940",6378245,298.3],
TOWGS84[23.57,-140.95,-79.8,0,-0.35,-0.79,-0.22]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
from nomk import coord
from osgeo import ogr, osr
epsg7683 = osr.SpatialReference()
epsg7683.ImportFromEPSG(4284)
epsg7683.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
# epsg7683.SetTOWGS84(23.57,-140.95,-79.8,0,0.35,0.79,-0.22)
epsg4326 = osr.SpatialReference()
from osgeo import ogr, osr
pt = ogr.CreateGeometryFromWkt('POINT(37.0 55.0)')
epsg7683 = osr.SpatialReference()
epsg7683.ImportFromEPSG(7683)
epsg7683.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
# epsg7683.SetTOWGS84(23.57,-140.95,-79.8,0,0.35,0.79,-0.22)
epsg4326 = osr.SpatialReference()
epsg4326.ImportFromEPSG(4326)
@BishopGIS
BishopGIS / test_warp.py
Created December 26, 2020 12:52
Test warp
from osgeo import gdal
import os
ds = gdal.Warp('', 'small.tif', format='MEM', warpOptions=["INIT_DEST=NO_DATA", "UNIFIED_SRC_NODATA=YES"], srcNodata=0, dstAlpha=True)
try:
os.remove('nd5.tiff')
except OSError:
pass
@BishopGIS
BishopGIS / test_scale_zoom.py
Created November 9, 2020 13:37
Test scale to zoom conversion
# -*- coding: utf-8 -*-
import math
dpi = 1000 / 39.37 / 0.28
ipm = 39.37
metersPerTile = 156543.04
def getZoomFromScale(scale):
return math.log(scale) / math.log(2)
bishop@Bishop-MacBookPro tmp % /usr/bin/env python /Users/Bishop/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/lib/python/debugpy/launcher 58870 -- /Volumes/Data/tmp/test_wfs.py
WFS: https://sandbox.nextgis.com/api/resource/6038/wfs?VERSION=1.0.0&SERVICE=WFS&REQUEST=GetCapabilities
HTTP: Fetch(https://sandbox.nextgis.com/api/resource/6038/wfs?VERSION=1.0.0&SERVICE=WFS&REQUEST=GetCapabilities)
HTTP: libcurl/7.71.1 OpenSSL/1.1.1c zlib/1.2.11
* Couldn't find host sandbox.nextgis.com in the .netrc file; using defaults
* Trying 5.9.138.126:443...
* Connected to sandbox.nextgis.com (5.9.138.126) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /Users/Bishop/Applications/NextGIS/Library/Frameworks/openssl.framework/Resources/ssl/certs/cert.pem
from osgeo import gdal
from osgeo import ogr
from osgeo import osr
base_url = 'https://sandbox.nextgis.com'
service = 6038
version = '1.0.0'
gdal.SetConfigOption("CPL_DEBUG", "ON")
gdal.SetConfigOption("CPL_CURL_VERBOSE", "YES")
from osgeo import osr
proj4 = ''
dst = osr.SpatialReference()
dst.ImportFromProj4(proj4)
dst.ExportToWkt()
@BishopGIS
BishopGIS / test_osr.py
Created May 5, 2020 18:37
Test coordinate transformation accuracy
from osgeo import gdal, osr
y = 7509137.5811
x = 4187591.89173
gsk2011 = '+proj=longlat +a=6378136.5 +rf=298.2564151 +towgs84=0.013,-0.092,-0.03,0.001738,0.003559,-0.004263,0.0074 +no_defs'
src = osr.SpatialReference()
dst = osr.SpatialReference()
src.ImportFromEPSG(3857)
@BishopGIS
BishopGIS / test.py
Created March 30, 2020 22:03
test numpy exists
import sys
import os
for path_item in sys.path:
try:
items = os.listdir(path_item)
for item in items:
if item == 'numpy':
print('numpy directory present in path: {}'.format(path_item))
# cut some lines from __init__.py