Skip to content

Commit

Permalink
Merge pull request #718 from rcoup/rc-remove-query
Browse files Browse the repository at this point in the history
remove query command
  • Loading branch information
olsen232 committed Oct 5, 2022
2 parents 433b74b + 3bcadcb commit 2fabc6c
Show file tree
Hide file tree
Showing 18 changed files with 9 additions and 528 deletions.
8 changes: 2 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Requirements for macOS & Linux:
* OpenSSL >= v1.1
* PostgreSQL client library (libpq)
* Python >= 3.7
* Spatialindex >= v1.9.3
* SpatiaLite >= v5.0.1
* SQLite3 >= v3.31.1
* SWIG
Expand Down Expand Up @@ -49,7 +48,7 @@ If you're a Homebrew user, you can get all of those via:

```console
$ brew install cmake gdal git openssl@1.1 libpq python@3.7 \
spatialindex libspatialite sqlite3 swig unixodbc
libspatialite sqlite3 swig unixodbc
```

Then configure Kart:
Expand All @@ -69,7 +68,7 @@ $ sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt-get install build-essential cmake ccache libgdal-dev gdal-data git \
libssl-dev libpq-dev python3.8-dev python3.8-venv \
libspatialindex-dev libsqlite3-mod-spatialite sqlite3 swig4.0 unixodbc
libsqlite3-mod-spatialite sqlite3 swig4.0 unixodbc
```

Then configure Kart:
Expand Down Expand Up @@ -176,7 +175,6 @@ Kart v0.9.1.dev0, Copyright (c) Kart Contributors
» GDAL v3.0.4
» PyGit2 v1.1.0; Libgit2 v0.99.0; Git v2.25.1.windows.1
» APSW v3.30.1-r3; SQLite v3.30.1; SpatiaLite v5.0.0-beta0
» SpatialIndex v1.8.5
```

### Linux
Expand All @@ -196,7 +194,6 @@ Kart v0.9.1.dev0, Copyright (c) Kart Contributors
» GDAL v3.0.4
» PyGit2 v1.1.0; Libgit2 v0.99.0; Git v2.25.1.windows.1
» APSW v3.30.1-r3; SQLite v3.30.1; SpatiaLite v5.0.0-beta0
» SpatialIndex v1.8.5
```

### Windows
Expand All @@ -222,7 +219,6 @@ Kart v0.9.1.dev0, Copyright (c) Kart Contributors
» GDAL v3.0.4
» PyGit2 v1.1.0; Libgit2 v0.99.0; Git v2.25.1.windows.1
» APSW v3.30.1-r3; SQLite v3.30.1; SpatiaLite v5.0.0-beta0
» SpatialIndex v1.8.5
```

## CI
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ py-install-docs = $(VIRTUAL_ENV)/.docs.installed
py-install-test = $(VIRTUAL_ENV)/.test.installed
py-install-tools = $(VIRTUAL_ENV)/.tools.installed

$(PY_REQS) $(py-install-main): export SPATIALINDEX_C_LIBRARY:=$(abspath $(VIRTUAL_ENV)/lib/libspatialindex_c.$(LIBSUFFIX))

$(py-install-main): requirements.txt $(vendor-install)
$(py-install-test): requirements/test.txt $(py-install-main)
$(py-install-docs): requirements/docs.txt $(py-install-main)
Expand Down Expand Up @@ -154,7 +152,7 @@ kart-cli-helper = cli_helper/kart_cli_helper
$(kart-cli-helper): cli_helper/kart.c.o cli_helper/cJSON.c.o | $(VIRTUAL_ENV)
$(CC) -o $@ cli_helper/kart.c.o cli_helper/cJSON.c.o

cli_helper/kart.c.o: cli_helper/kart.c
cli_helper/kart.c.o: cli_helper/kart.c
$(CC) -Wall -o $@ -g -c $<

cli_helper/cJSON.c.o: cli_helper/cJSON.c
Expand Down
12 changes: 2 additions & 10 deletions kart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@
# sys.prefix is correctly set by virtualenv (development) & PyInstaller (release)
prefix = os.path.abspath(sys.prefix)

# Rtree / Libspatialindex
if not is_windows:
if _kart_env:
os.environ["SPATIALINDEX_C_LIBRARY"] = _kart_env.SPATIALINDEX_C_LIBRARY
else:
os.environ["SPATIALINDEX_C_LIBRARY"] = os.path.join(
prefix, "" if is_frozen else "lib", f"libspatialindex_c.{libsuffix}"
)

if _kart_env:
spatialite_path = os.path.splitext(_kart_env.SPATIALITE_EXTENSION)[0]
else:
Expand Down Expand Up @@ -113,7 +104,8 @@

if is_linux:
import certifi
os.environ['SSL_CERT_FILE'] = certifi.where()

os.environ["SSL_CERT_FILE"] = certifi.where()

# Libgit2 options
import pygit2
Expand Down
7 changes: 1 addition & 6 deletions kart/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"show": {"create-patch", "show"},
"spatial_filter": {"spatial-filter"},
"status": {"status"},
"query": {"query"},
"upgrade": {"upgrade"},
"tabular.import_": {"import"},
"point_cloud.import_": {"point-cloud-import"},
Expand Down Expand Up @@ -89,7 +88,6 @@ def print_version(ctx):
import osgeo
import psycopg2
import pysqlite3
import rtree

import sqlalchemy
from kart.sqlalchemy.gpkg import Db_GPKG
Expand All @@ -103,8 +101,6 @@ def print_version(ctx):
.split()[-1]
)

sidx_version = rtree.index.__c_api_version__.decode("ascii")

engine = Db_GPKG.create_engine(":memory:")
with engine.connect() as conn:
spatialite_version = conn.scalar("SELECT spatialite_version();")
Expand All @@ -130,8 +126,7 @@ def print_version(ctx):
f"» SQLAlchemy v{sqlalchemy.__version__}; "
f"pysqlite3 v{pysqlite3.version}/v{pysqlite3.sqlite_version}; "
f"SpatiaLite v{spatialite_version}; "
f"Libpq v{pq_version}\n"
f"» SpatialIndex v{sidx_version}"
f"Libpq v{pq_version}"
)
)

Expand Down
2 changes: 0 additions & 2 deletions kart/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def helper(ctx, socket_filename, timeout, args):
"PATH",
"LD_LIBRARY_PATH",
"LD_LIBRARY_PATH_ORIG",
"SPATIALINDEX_C_LIBRARY",
"GIT_CONFIG_NOSYSTEM",
"GIT_EXEC_PATH",
"GIT_TEMPLATE_DIR",
Expand Down Expand Up @@ -98,7 +97,6 @@ def helper(ctx, socket_filename, timeout, args):
import osgeo
import psycopg2
import pysqlite3
import rtree

import sqlalchemy
from kart.sqlalchemy.gpkg import Db_GPKG
Expand Down
109 changes: 0 additions & 109 deletions kart/query.py

This file was deleted.

64 changes: 0 additions & 64 deletions kart/tabular/rich_table_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class RichTableDataset(TableDataset):
this functionality isn't needed. For example, see Dataset0.
"""

RTREE_INDEX_EXTENSIONS = ("kart-idxd", "kart-idxi")

def features_plus_blobs(self):
for blob in self.feature_blobs():
yield self.get_feature(path=blob.name, data=memoryview(blob)), blob
Expand Down Expand Up @@ -83,68 +81,6 @@ def _cols_to_crs_ids(self):
result[col.name] = crs_id
return result

def build_spatial_index(self, path):
"""
Internal proof-of-concept method for building a spatial index across the repository.
Uses Rtree (libspatialindex underneath): http://toblerity.org/rtree/index.html
"""
import rtree

if not self.has_geometry:
raise ValueError("No geometry to index")

def _indexer():
t0 = time.monotonic()

c = 0
for feature in self.features():
c += 1
pk = feature[self.primary_key]
geom = feature[self.geom_column_name]

if geom is None:
continue

e = geom.envelope(only_2d=True, calculate_if_missing=True)
yield (pk, e, None)

if c % 50000 == 0:
print(f" {c} features... @{time.monotonic()-t0:.1f}s")

p = rtree.index.Property()
p.dat_extension = self.RTREE_INDEX_EXTENSIONS[0]
p.idx_extension = self.RTREE_INDEX_EXTENSIONS[1]
p.leaf_capacity = 1000
p.fill_factor = 0.9
p.overwrite = True
p.dimensionality = 2

t0 = time.monotonic()
idx = rtree.index.Index(path, _indexer(), properties=p, interleaved=False)
t1 = time.monotonic()
b = idx.bounds
c = idx.count(b)
del idx
t2 = time.monotonic()
print(f"Indexed {c} features ({b}) in {t1-t0:.1f}s; flushed in {t2-t1:.1f}s")

def get_spatial_index(self, path):
"""
Retrieve a spatial index built with build_spatial_index().
Query with .nearest(coords), .intersection(coords), .count(coords)
http://toblerity.org/rtree/index.html
"""
import rtree

p = rtree.index.Property()
p.dat_extension = self.RTREE_INDEX_EXTENSIONS[0]
p.idx_extension = self.RTREE_INDEX_EXTENSIONS[1]

idx = rtree.index.Index(path, properties=p)
return idx

@functools.lru_cache()
def get_geometry_transform(self, target_crs):
"""
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ pyrsistent==0.18.1
# via jsonschema
rst2txt==1.1.0
# via -r requirements/requirements.in
rtree==0.9.7
# via -r requirements/requirements.in
shellingham==1.5.0
# via -r requirements/requirements.in
sqlalchemy==1.4.40
Expand Down
1 change: 0 additions & 1 deletion requirements/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ cryptography
msgpack~=0.6.1
pymysql
Pygments
Rtree~=0.9.4
sqlalchemy
pyodbc ; platform_system!="Linux"
shellingham
Expand Down
1 change: 0 additions & 1 deletion requirements/run.apt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
git-core
libspatialindex-c4v5

0 comments on commit 2fabc6c

Please sign in to comment.