How to get shape country (without maritime limit...only terrain) in Overpass? - openstreetmap

I am trying to get the shape of country in Overpass API without the maritime limit in http://overpass-turbo.eu
And I have this query but it shows the maritime:
relation
["boundary"="administrative"]
["admin_level"="2"]
["name:en"="Spain"];
(._;>;);
out body;

I found it, thanks to OpenStreetmap spanish mailing list and the doc (it is in spanish) https://iceosm2016.readthedocs.io/en/latest/ .
area["name"="España"]->.country;
rel["name"="España"]["type"="boundary"]["admin_level"="2"];
(
way(r)["maritime" != "yes"]({{bbox}});
way(area.country)["natural"="coastline"]({{bbox}});
);
out geom;

You could try to use a dedicated relation for Península ibérica instead:
relation
["wikidata"="Q12837"];
(._;>;);
out body;

Related

Strapi - How to GET data sorted based on relation property?

I have an Articles table and it has a relation with the Authors table. Each author has a name property. I want to make a GET request for the articles and receive the articles sorted based on their author's name.
When I use _sort=author in the url parameters, I get the articles sorted based on the author object's ID.
When I use _sort=author.name in the url parameters, I get the articles in a seemingly random order but definitely not based on author.name.
How can I get the data sorted based on author.name?
I use mongoDB as my database.
That is the default behavior of _sort. However, you can simply accomplish this by overriding the find method in api/article/services/article.js to sort by Author's name like so:
module.exports = {
async find(params, populate) {
let result = await strapi.query('article').find(params, populate);
if (params._sort == 'author')
return result.sort((a, b) => (a.author.name > b.author.name) ? 1 : -1);
return result;
},
}
Check the documentation for customizing services to get more info: https://strapi.io/documentation/v3.x/concepts/services.html#concept

TypeORM Postgres filter by relation count

context
I have Users collection and Recipe collection, ManyToMany relation between them
I'm new in this framework, wondering how can I do the following query:
count users with at least one recipe
count users without any recipes
I have found loadRelationCountAndMap is very useful in counting how many recipes a user has, but I can't seem to filter the total response according to this property.
I have tried this:
const users_without_recipes = await getRepository(User)
.createQueryBuilder('user')
.addSelect(['user.createdAt', 'user.email'])
.loadRelationCountAndMap('user.recipes_count', 'user.recipes')
.where('user.recipes_count = :count', {count: 0})
.getManyAndCount();
also tried to use postgres array_count but not sure how to integrate it with the typeORM framework
and help is very appreciated
You can do this with subqueries I think.
Something like this in SQL:
SELECT *
// ... other stuff
WHERE user.id IN (
SELECT u.id
FROM user u JOIN recipie r USING(id)
GROUP BY u.id
HAVING COUNT(*) > 10
)
Or in TypeORM:
// ...
.where(qb => {
const subQuery = qb.subQuery()
.select("u.id")
.from(User, "u")
// join users and recipies
.groupBy("u.id")
.having("COUNT(*) > :count", { count: 10 })
.getQuery();
return "user.id IN " + subQuery;
});
//...
I have stumbled upon this exact problem myself. I have fond a couple of sources that could help you find the solution. Your underlying problem is more general. If you turn on logging, you will probably see an error message something like:
Error column "user"."recipes_count" does not exist
The problem is that you are trying to use an alias. This question deals with this problem:
Using an Alias in a WHERE clause
I hope you are more successful then me, but I decided to use a workaround after a log trial and error. I am sure there is a better way. If you manage to find it, please let me know.
(If you want to get back the list of user entities, without the user.recipes_count property, include the last .map as well.)
const users_without_recipes = await getRepository(User)
.createQueryBuilder('user')
.loadRelationCountAndMap('user.recipes_count', 'user.recipes')
.getMany();
return users_without_recipes
.filter((user) => user['user.recipes_count'] === 0)
.map(({recipes_count, ...otherProperties}) => otherProperties);

Tinkerpop Frames #Adjacency to Orientdb LINKLIST

Is there a way to map Tinkerpop Frames's #Adjacency annotated property to Orientdb LINKLIST? Right now I've something like this:
interface Person {
#Adjacency(label = "personCars", direction = Direction.OUT)
Iterable<Car> getCars();
#Adjacency(label = "personCars", direction = Direction.OUT)
void addCar(Car car);
}
I want this to be mapped to LINKLIST in Orientdb database to keep an order of added vertices. But this is by default mapped to LINKBAG type. Is there any clean solution to set Orientdb to map adjacencies to LINKLISTs?
OrientDB, by default, uses a set to handle the edge collection. Sometimes it's better having an ordered list to access the edge by an offset. Example:
person.createEdgeProperty(Direction.OUT, "Photos").setOrdered(true);
Every time you access the edge collection the edges are ordered. Below is an example to print all the photos in an ordered way.
for (Edge e : loadedPerson.getEdges(Direction.OUT, "Photos")) {
System.out.println( "Photo name: " + e.getVertex(Direction.IN).getProperty("name") );
}
To access the underlying edge list you have to use the Document Database API. Here's an example to swap the 10th photo with the last.
// REPLACE EDGE Photos
List<ODocument> photos = loadedPerson.getRecord().field("out_Photos");
photos.add(photos.remove(9));
From the official documentation.

How to insert a vertex with link type property with the orientjs query builder?

I am trying to insert a vertex with orientjs(previously oriento) query builder. My class has a link type property pointing to another class.
I know I can get it to work with a raw query string but I would love to use the query builder.
Here is what I've tried so far :
db.insert()
.into('VertexClassName')
.set({"prop":"value", "linkProperty":"33:1289287"})
db.insert()
.into('VertexClassName')
.set({"prop":"value", "linkProperty":"#33:1289287"})
I get the following error :
Error on saving record in cluster #13
Am I setting properties in the right way ?
Could the error be related to somtehing else ?
I have sucessfully ran an insert query in the cluster #13 with a raw query string in the studio...
According to the official documentation it seems that the problem might be at the end of your statement
db.insert().into('VertexClassName')
.set({"prop":"value", "linkProperty":"33:1289287"}).one()
.then(function (data) {
// callback
});
Check if your code works adding one() to the pipe line
EDITED: I found this method in orientjs.
db.create('VERTEX', 'V')
.set({
key: 'value',
foo: 'bar'
})
.one()
.then(function (vertex) {
console.log('created vertex', vertex);
});
When using Tinkerpop API they recommend using createVertex instead of insert, because createVertex is intended for graphs and insert for Documents... Could you try with the create() method instead?
I am using SQL and it worked.
sql = "INSERT INTO Station set linked = (select from LinkedClass where LinkedProb = 'value'), prop = 'value'"
OrientVertex vertex = new OrientVertex();
vertex = graph.command(new OCommandSQL(sql)).execute();
I don't think that's possible unless you've added a proper field with the right type 'Link' in your schema. (which I rarely do).
Now instead of having the right 'link' type inserted you can do the opposite, store is as a String, and leverage the query functions to use it correctly:
db.insert().into('table').set({prop: '#15:14'}).one();
And it will be converted as String (which is a bit sad) but then you can use that in your queries:
SELECT eval(prop) FROM table;
And it will be 'eval'-ed to a Node RecordID that you can directly use and call functions like expand() on.
For example:
SELECT name FROM (SELECT expand(eval(prop)) FROM table);
Will eval the node stored in the insert(), grab the node, expand it and collect its name property.

ArangoDB create Vertex REST API without knowing the vertex id's

Is there a way to create with ArangoDB an Edge with REST API without knowing the Vertex ids? With a query to find the vertexs and link them?
Like this with OrientDB: create edge Uses from (select from Module where name = 'm2') to (select from Project where name = 'p1')
I don't want to query via REST the two vertex before, and after create the Edge. I don't want to use Foxx also.
Perhaps with AQL?
Thanks.
Yes, it is doable with a single AQL query:
LET from = (FOR doc IN Module FILTER doc.name == 'm2' RETURN doc._id)
LET to = (FOR doc IN Project FILTER doc.name == 'p1' RETURN doc._id)
INSERT {
_from: from[0],
_to: to[0],
/* insert other edge attributes here as needed */
someOtherAttribute: "someValue"
}
INTO nameOfEdgeCollection