How to add a property attribute to the whole feature collection while exporting a geojson through geopandas? - geojson

I am using geopandas and created a GeoDataFrame which contains the following columns:
id
geometry
When exported to a geojson using GeoDataFrame.to_file(), the rows of the dataframe as exported as a list of 'features' and the type of geojson is a 'FeatureCollection'. I want to add attributes in the properties of the 'FeatureCollection' and not the 'features'.
E.g. I would like to add a date attribute to this 'FeatureCollection'.
If I create an extra 'date' column, it is added as a property inside each feature. How can I add this attribute as a 'global' attribute for all features.
P.S. I am new to geopandas.

Related

How to create a 'group' using calculated field

I've created groups to bundle similar values together, e.g. product names containing specific keywords. However, product names are always changing and I don't want to have to manually update the groups with new product names.
I would like to use a calculated field which has the "CONTAINS()" function (or something similar to this functionality) in the group in order to have it updated when new values are found. How can this be done?

How to create a table in SQL Database from a CSV file in Blob which contain all the column name with its data type through Data Flow or ADF pipeline?

I am having a CSV file in my Azure Blob Storage which contain all the column name with its data Data type of respective tables.
I want to create a table in SQL Database from this Blob file with the same column name with its corresponding datatype without doing the mapping.
I have created a table through data flow but I have to set the data type of each column manually. But I don't want to do this.
When I create a table it should accept the same data types in the source as well as synch which was given in the CSV file.
[]
[]
When I import the schema it takes full column as ID (int) and data type as String but I want when I import the schema and create a table it will take column name as ID and data type as INT and it will do same all column names for multiple tables.
Please let me know if you have a solution to this problem.
In Data Factory, when we copy data from the CSV file, we set first row as column, that means that the first row data will be set as column name, id(int) and Name(varchar). As you know, the default column name data type is String(in Data Factory)/varchar(128)(in SQL database), we can not change it.
We can not create the table with schema as column name! There's no solution to this problem.
But Data Factory will auto help us create the suitable column data type mapping for us.
For example, if your csv file is like this:
Auto schema mapping will convert "1"(string) to 1(int) in Azure SQL database.
Hope this helps.

Loop over all model fields in Rails/MongoDB

I am using mongoid/Rails for my application server. I defined my own field typ 'formula'. This is a field I don't want to have persistent in the database since this is not a data field but a formula which is consistent across all records of a model. So I stored this formula in my metadata and whenever I create dynamically a model where I need this formula I create a field with my custom type 'formula' where the formula is the default value. This works so far - but as soon as I save a record which includes my formula field it doesn't.
So before I create or update any records I want to loop over all fields of my model and depending on the type the field I allow it to be updated - or not ( so for every formla field I don't allow updates)
I can loop over all field names (model.fields.keys.each) and check the name of the field - But I haven't found a method to loop over all fields and access the type. Any idea?
But perhaps there is another way to avoid my formula field is saved in the database? I create a mongoize (object) method for my new field type 'formula' and this method simply returns nil - but this still writes an empty field to the database.

Is it possible to restrict CoreData entries to a single entity attribute?

Is it possible to restrict a Core Data entry to a single attribute? For example, let's say I have this entity:
Entity
Attribute: name
and there are multiple Entity objects that can be added to the database via a one-to-many relationship. Can I restrict the data entries so that only Entity with different name attributes can be added? I don't want to query the data base every time something is added, because that would cause a performance impact when the database gets larger.
Thanks!
No, you can't.
For now I would have the following ideas.
1 - If the attribute is a string, you should make it as a canonical form (a plain text without accents, etc.). Then you can search with predicates like startsWith or endsWith.
2 - You could add another attribute in entity that you use as a hash value. That hash will be generated when you insert a new object. When you insert a new value, you will check against value.
3 - Indexing the attribute to improve performances.
Core Date cannot check automatically for duplicate values, so you have to check first
if an object with a given value exists before inserting a new one.
If you have to insert many objects, then it is more efficient to fetch all objects having
values from the new list first instead of many fetch requests.
This is described in "Implementing Find-or-Create Efficiently" in the "Core Data Programming Guide".

Possible to create a calculated field in a doctrine query you can then retrieve as an object attribute?

Suppose you declare a simple "license" table in a doctrine schema, consisting say of 3 fields, name, licenseNumber, expirationDate.
You can create a simple query to instantiate the collection of license objects. But what if you wanted to add a "virtual" field to it, for example,select *, (now() > expirationDate) as expired from license (in DQL, I'm using SQL as shorthand here).
Is there any way to get doctrine to make the "expired" calculated field retrievable as an attribute of the object? This is a trivial example to illustrate the point, but it could be quite helpful for more complicated calculated queries, or else I'm misunderstanding something.
No, there is no way to do what you are asking without adding a custom method to hydrate the "virtual column". Take a look at this SO post, as it gives an excellent example on how to hydrate arrays with your "virtual column".
You can also add the "virtual column" as a member object to the respective class and hydrate it like this example demonstrates.
You can also use a view with such a column and map your model to it instead of a db table

Resources