Which is the best way to work with PostGIS and OpenLayers? - postgresql

I have a postgresql db table with a City table that has a geography field with the city coordinates.
I have made a php page that loops through these records, converts geo field in latit/longit and draws a marker in an OpenLayers map to the city during an ajax call.
I don't know if this is the correct way to do it: is there a way to directly bind the sql query to the map without having to loop?
Is there a more direct relation between the database and the OpenLayers maps?

I am not sure about what is the software stack that you are using, but usually, OpenLayers do not work directly with PostGIS.
A common configuration is PostGIS -> GeoServer -> OpenLayers
GeoServer will get your data from the database (or many other sources) and publish it in a valid format for openlayers like wms.
For more specific questions you can post your question in https://gis.stackexchange.com/

Related

Postgis wire data types

I am implementing a java client for postgres and added postgis support.
I am trying to figure out the wire protocol types that are returned for geometric data types.
It looks like different postgis versions has different type number returned.
In some version it was 18011 and another has 17995 for line string. You can see related test I did here:
// previous
PostgreSQLColumnDecoderRegistry.Instance.registerDecoder(18011, JtsColumnDecoder())
// current
PostgreSQLColumnDecoderRegistry.Instance.registerDecoder(17995, JtsColumnDecoder())
IIUC the types can be seen on the db itself here on pg_type table: https://www.postgresql.org/docs/current/catalog-pg-type.html
Do you know where I can find docs / code about the type numbering rules?
The object IDs of the PostGIS data types are dynamically allocated when you create the extension. Consequently, they will normally be different in different PostgreSQL databases. One of the simplest queries to find the object ID of geometry is
SELECT 'geometry'::regtype::oid;

what possible ways to include external tables in TYPO3

Since TYPO3 uses doctrine it is possible to use tables from multiple databases in one instance (with some restrictions like no joins).
But what is possible at all?
At the moment I need two external tables for an extension and instead of using them directly I import them to work locally as usual. But the importing has some draw backs.
Draw backs I can accept:
the data is not live (changes to the external tables are imported later)
the data is read only (changes are done externally anyway)
For importing I use ext:external_import but there are some problems as not all data can be imported in a single run, and then there are errors (e.g. there are reports about duplicate keys, alas there are no duplicate keys in the external tables)
On the other hand I doubt I can use the external tables directly as they have not the usual TYPO3 structure (fields: 'uid', 'pid', 'tstamp', ...). (Maybe they can be mapped in a view?) (of course in the tables I import the data into these fields exist)
Also external changes may be unnoticed and cached content does not reflect current data. In my case that would be a minor problem, as we currently already have no 'live' data, but this needs to be cleaned regularly for cache and for the search index (solr).
What are possible solutions? ? (do they depend on the TYPO3 version?)
What are your experiences?
EDIT:
While trying to realize it considering the given answers more doubts appear:
the tables are readonly (as they are changed from outside):
How do I declare it to TYPO3?
the tables does not follow the usual name rules, especially one table is named sys_category which in this way conflicts with the TYPO3 table sys_category.
Can I build a mapping inside of TYPO3?
Can I build a view from TYPO3 for renaming tables and fields?
like:
CREATE View tx_myext_category
SELECT id as uid, name as title, ...
FROM databasename.sys_category;
Yes, you can fetch data directly from other databases/tables. Of course it highly depends on the usecases and the data you get:
It works fine to read/write data by using the queryBuilder and all the APIs you know from https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/Index.html like ConnectionPool, QueryBuilder
If you want to show the data in the formengine, e.g. list module, you will need to have the minimum columns like uid, pid and a valid TCA as well.
From my experience, the mapping mechanism only works if the external table has a almost similar structure as TYPO3 tables. You need at least a uid field on the external side. This cannot be mapped! A missing pid field could be managed with on the TYPO3 side, also crdate or tstamp if needed. Just fill the local data array with the values TYPO3 needs.
Problems arise if you have relations to deal with. Many external systems have other ways to handle relations. You could run into many problems if you try to rely only on the mapping mechanism.
Other problems are fields with date format. Most external tables in the MS world use another format as the unixtime.
If you run into problems with the mapping mechanism you can switch to the TYPO3 queryBuilder. This is a powerful fallback. I experienced problems only with a special type of JOIN statements.
But with the TYPO3 queryBuilder you are on your own. You place instances of the queryBuilder code in the repository and add your model code as usual: thus you can continue to work with Fluid in the frontend as you are used to.
ANSWER TO EDIT:
With the TYPO3 queryBuilder readonly tables aren't a problem. Just don't implement the setter classes in your models.
With TYPO3 queryBuilder you can call any external table with any name. You have full control over the output data in your repository because the mapping is handled inside of it.
As far as I know, there is no way to create SQL views in TYPO3 up to v9, neither with the DBAL mapping mechanism nor with the TYPO3. queryBuilder.

EF 6 Database First - map stored procedure to existing objects

Hi I have a project which is quite old. It uses stored procedures which isn't an issue but it does have lots of error prone mapping code in old ADO.net. My main goal is to cut down the mapping more than anything. We have a separate library of I guess POCO/DTO type objects that get mapped to.
Can I map stored procedures to these classes easily. I suppose I could use AutoMapper as the mapping will be exact but I'm wondering if there's an easier way that it does out of the box. The list of complex type doesn't show the imported library's business classes. Cheers.
Instead of using AutoMapper, create a complex return type using "Edit Function Import", which has the exact properties as the stored procedure result.

CRUD operation Grails

I need to read data from existing database is it possible using
compile "org.grails.plugins:db-reverse-engineer:4.0.0"?
My operations are: user should read data from existing table, create new record, create new coulmn, edit coulmn name, edit records.
View format will be in grid like xml grid.
Which technology is the best for these operations in grails, I have plan to work on javascript using jaxrs, is it good to do?
DB Reverse Engineering Plugin (org.grails.plugins:db-reverse-engineer:4.0.0) allows you to generate domain classes using existing DB. After you generate them - just use GORM to perform CRUD operations. You can read about GORM here
You can implement REST api in Grails using standart ways, check this answer to get high level understanding. If you need jaxrs- there is a plugin for that.

Shape File Data Map to Osm Data For Routing

I am Working Routing application it is Basically Working on .osm File . I have shape file file so need to be changes used QGIS Desktop Application . But I have no idea Shape file Which Attributes map to OSM data Attributes
Following Tag Used For OSM Data Routing
Way types
highways
Routing
oneway,junction,maxspeed,bridge,tunnel,surface,access
Relations
type
Directions
lanes,name,name_1,ref
Relations
type