Skip to content

Instantly share code, notes, and snippets.

View kylefelipe's full-sized avatar
😀

Kyle Felipe kylefelipe

😀
View GitHub Profile
@kylefelipe
kylefelipe / Installation.md
Last active February 14, 2024 17:18
Instalando XDEBUG no ubuntu - XAMPP (LAMPP)
@kylefelipe
kylefelipe / README.md
Created May 2, 2023 20:10
Renomeando camadas em um geopackage

Renomear várias camadas em um geopackage

SELECT 
'ALTER TABLE '|| table_name || ' RENAME TO ''' || replace(table_name, '2021', '2020') ||''';'
FROM gpkg_geometry_columns
WHERE table_name like '%2021';

Esse SQL vai buscar os nomes das tabelas em gpkg_geometry_columns e criar o sql de renomeação para cada uma das tabelas que passarem no WHERE.

@kylefelipe
kylefelipe / Expressao_qgis.sql
Created January 26, 2023 21:06
Pega Nome da camada dinamicamente -- QGIS
with_variable('lyr_name', -- variável que vai pegar o nome do estado
aggregate(
layer:='lim_unidade_federacao_a', -- nome da camda do estado
aggregate:='min',
expression:="sigla", -- campo que quer usar para gerar o nome da camada
filter:=contains($geometry, geometry(@parent))
),
with_variable('lyrmaps', -- vai receber o nome de todas as camadas no projeto
array_foreach(@layers, layer_property(@element, 'name')), --pega o nome de todas as camadas do projeto em uma lista
with_variable('lyrpos', array_find(@lyrmaps, upper(@lyr_name)), -- lirpos procura o nome da camada na lista e retorna a posicao, se nao encontrar retorna -1
@kylefelipe
kylefelipe / README.md
Created January 20, 2023 18:41
Script sh não salva os prints do arquivo python quando é executado pelo crontab

O agendamento do crontab está da seguinte forma

*/15 * * * * cd /root/pasta_script;  ./script.sh --cron

o script sh tem permissão para execução.....

Quando executo o arquivo .sh manualmente, o arquivo de log recebe todos os prints que o arquivo python gera, quando o script é executado

@kylefelipe
kylefelipe / validate.js
Last active July 6, 2022 23:01
Valida aberturas e fechamentos de colchetes em uma string
// adaptado de https://github.com/tryber/sd-05-live-lectures/blob/39.1/expressoes.py
const MATCHES = {
'}': '{',
']': '[',
')': '(',
'"': '"',
"'": "'",
"`": "`",
"```": "```"
};
@kylefelipe
kylefelipe / SELECTION.sql
Last active June 14, 2022 19:20
Selecting features from table A using table B
-- Expression to be used at SELECT BY EXPRESSION AT LAYER A
array_contains( -- This will return true if the array contains the value
aggregate( -- will aggregate all values from target in to a string, using semicolons as concatenator
layer:='<table_b>', -- Target table containing the values, replace <table_b> whith your table name
aggregate:='array_agg',
expression:=to_string("<field_from_table_b>"), -- Field from table_b containing the values
),
"<field_table_a>") -- Field from table a with values to compare, replace <field_table_a> with your field name
@kylefelipe
kylefelipe / README.md
Last active October 25, 2021 22:47
Criando uma camada virtual a partir de uma query SQL usando PyQGIS

SQL + Virtual Layers + PyQGIS

# Estados que queremos pegar os municípios
nomes = ['Minas Gerais', 'Paraíba', 'Espírito Santo', 'Goiás', 'Sergipe']
nomes = [f"'{nome}'" for nome in nomes]

# Pegando apenas as feições que precisamos 
estados = QgsProject.instance().mapLayersByName('lim_unidade_federacao_a')[0]
subset_string = f"nome in ({','.join(nomes)})"
@kylefelipe
kylefelipe / README.md
Last active October 20, 2021 18:28
GeoServer - extension issue - gs-querylayer

This is a issue using cross-layer filter provided by querylayer extension

Layers

LayerA - intersection_geom -> GEOMETRY, layer geometry;
LayerB - cd_bioma -> INTEGER, biome code; geom -> GEOMETRY, layer geometry;

CQL_Filter

intersects(intersection_geom, querySingle(layerB, 'geom', 'cd_bioma=1'))

@kylefelipe
kylefelipe / rename_imgs.py
Last active September 16, 2021 22:18
This script rename files using a csv list that contains img_Id, file_name, new_name, receiving_folder it will create all new folders needed to paste the copies And paste them inside the receiving_folder
# This script rename files using a csv list that contains
# img_Id, file_name, new_name, receiving_folder
# it will create all new folders needed to paste the copies
# And paste them inside the receiving_folder
# Created by Kyle Felipe
# kylefelipe at gmail.com
import os
import csv
from shutil import copy2 as copy
@kylefelipe
kylefelipe / a_sequelize_issue.md
Last active May 7, 2021 21:15
Sequelize issue about N:N relations

Here is my issue:
I wish to delete all rows at row-group-view if i delete a group from group or if i delete a view from view.